• 【原】测试Application.Idle


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

    /*
     Wrote by jamesking 2010-10-17.
     Mail:jamesking.chao@gmail.com
     */
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace 测试Application.Idel
    {
        public partial class Form1 : Form
        {
            private int excuteTimes = 0;//空闲期间执行的次数
    
            public Form1()
            {
                InitializeComponent();
            }
    
            /// <summary>
            /// 时间处理,获取最新的系统时间在文本框中显示
            /// </summary>
            private void ProcessTime(object sender, EventArgs e)
            {
                textBox1.Text = System.DateTime.Now.ToString();
                excuteTimes++;
                if (excuteTimes == 9)
                {
                    Application.Idle -= new EventHandler(ProcessTime);
                    MessageBox.Show("已经在CPU空闲期间执行了10次!");
                }
            }
    
            /// <summary>
            /// 按扭,获取时间
            /// </summary>
            private void btnGetTime_Click(object sender, EventArgs e)
            {
                Application.Idle += new EventHandler(ProcessTime);
            }
        }
    }

     

  • 相关阅读:
    pydbg系列[1]
    内核参与方式
    Debugging with GDB阅读[6]
    宏技巧解读
    右键-发送到-邮件接收者没有了的解决方法
    获得文件版本信息
    解决动态生成的SQL中特殊字符的问题 QuotedStr function
    CreateFileMapping的MSDN翻译和使用心得
    关闭Windows自动播放功能
    清凉明目茶
  • 原文地址:https://www.cnblogs.com/fitel/p/2733945.html
Copyright © 2020-2023  润新知