zoukankan      html  css  js  c++  java
  • MethodInvoker 委托

    MethodInvoker 提供一个简单委托,该委托用于调用含 void 参数列表的方法。 在对控件的 Invoke 方法进行调用时或需要一个简单委托又不想自己定义时可以使用该委托。

    下面的代码示例演示如何使用 MethodInvoker 以调用更新应用程序窗体的标题栏的方法。

    public partial class Form1 : Form
    {
       private System.Threading.Timer timer;
        public Form1()
        {
            // Create a timer that will call the ShowTime method every second.
               timer = new System.Threading.Timer(ShowTime, null, 0, 1000);           
        }
    
        private void ShowTime(object x)
        {
            // Don't do anything if the form's handle hasn't been created 
            // or the form has been disposed.
            if (!this.IsHandleCreated && !this.IsDisposed) return;
    
            // Invoke an anonymous method on the thread of the form.
            this.Invoke((MethodInvoker) delegate
            {
                // Show the current time in the form's title bar.
                this.Text = DateTime.Now.ToLongTimeString();
            });
        }
    }
  • 相关阅读:
    HDU2059(龟兔赛跑)
    pat 1012 The Best Rank
    pat 1010 Radix
    pat 1007 Maximum Subsequence Sum
    pat 1005 Sign In and Sign Out
    pat 1005 Spell It Right
    pat 1004 Counting Leaves
    1003 Emergency
    第7章 输入/输出系统
    第六章 总线
  • 原文地址:https://www.cnblogs.com/weekend001/p/3521301.html
Copyright © 2011-2022 走看看