跨线程访问控件
namespace WindowsFormsApplication4 { public { public Form1() { InitializeComponent(); } private { Thread thd = new thd.Start(); } private { Invoke(new } } } |
异步
namespace WindowsFormsApplication3 { public { public Form1() { InitializeComponent(); } private { printdatetime(); } private { this.button1.Enabled = false; await pt(); this.button1.Enabled = true; } private { Task tk = Task.Run( () => { for(int i=0;i<100;i++) { Thread.Sleep(1000); this.label1.Text=DateTime.Now.ToString(); } } ); return tk; } } } |