本文整理匯總了C#中System.Windows.Forms.MethodInvoker代理的典型用法代碼示例。如果您正苦於以下問題:C# MethodInvoker代理的具體用法?C# MethodInvoker怎麽用?C# MethodInvoker使用的例子?那麽, 這裏精選的代理代碼示例或許可以為您提供幫助。
MethodInvoker代理屬於System.Windows.Forms命名空間,在下文中一共展示了MethodInvoker代理的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Form1
public partial class Form1 : Form
{
public Form1()
{
// Create a timer that will call the ShowTime method every second.
var 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();
});
}
}