最近在DoNet项目中需要用到Application.Idle功能函数,平时基本没用过。今天写点代码测试一下,一目了然。
Application.Idle的英文描述为:“Occurs when the application finished processing and is about to enter idle state.”,字面意思 当应用程序处于空闲状态时执行相应代码。
还是上代码,源代码也可直接下载。

usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespace测试Application.Idel{publicpartialclassForm1:Form{privateintexcuteTimes=0;//空闲期间执行的次数publicForm1(){InitializeComponent();}///<summary>///时间处理,获取最新的系统时间在文本框中显示///</summary>privatevoidProcessTime(objectsender,EventArgse){textBox1.Text=System.DateTime.Now.ToString();excuteTimes++;if(excuteTimes==9){Application.Idle-=newEventHandler(ProcessTime);MessageBox.Show("已经在CPU空闲期间执行了10次!");}}///<summary>///按扭,获取时间///</summary>privatevoidbtnGetTime_Click(objectsender,EventArgse){Application.Idle+=newEventHandler(ProcessTime);}}}


附件:http://down.51cto.com/data/2361603