码迷,mamicode.com
首页 > 移动开发 > 详细

WinForm中Application.Idle事件用法

时间:2017-09-02 00:07:07      阅读:284      评论:0      收藏:0      [点我收藏+]

标签:++   get   datetime   back   必须   进入   time   image   box   

Application.Idle 事件

描述:当应用程序完成处理并即将进入空闲状态时发生。如果您有必须执行的任务在线程变为空闲之前,请将它们附加到此事件。

 1     public partial class Form1 : Form
 2     {
 3         /// <summary>
 4         /// 空闲期间执行的次数
 5         /// </summary>
 6         private int executeTimes = 0;
 7 
 8         public Form1()
 9         {
10             InitializeComponent();
11         }
12 
13         private void btnGetTime_Click(object sender, EventArgs e)
14         {
15             Application.Idle += Application_Idle;
16         }
17 
18         /// <summary>
19         /// 当程序完成处理并进入空闲状态时发生
20         /// </summary>
21         /// <param name="sender"></param>
22         /// <param name="e"></param>
23         private void Application_Idle(object sender, EventArgs e)
24         {
25             txtTime.Text = DateTime.Now.ToString();
26 
27             executeTimes++;
28             if (executeTimes==9)
29             {
30                 Application.Idle -= Application_Idle;
31                 MessageBox.Show("已经在CPU空闲时间执行10次");
32             }
33         }
34     }

技术分享

WinForm中Application.Idle事件用法

标签:++   get   datetime   back   必须   进入   time   image   box   

原文地址:http://www.cnblogs.com/wgx0428/p/7465351.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!