界面假死的代码:
void btnSecondEventMode_Click(object sender, EventArgs e) { btnSecondEventMode.BackColor = Color.Coral; Thread.Sleep(5000); MessageBox.Show("hello world"); }
WinForm 异步调用
void BtnSecondEventAsyncModel_Click(object sender, EventArgs e) { Action action = () => { Task.Run(() => { BtnSecondEventAsyncModel.BackColor = Color.Coral; Thread.Sleep(5000); MessageBox.Show("hello world"); }); }; BeginInvoke(action); }
WPF 异步调用
void BtnSecondEventAsyncModel_Click(object sender, EventArgs e) { Action action = () => { Task.Run(() => { BtnSecondEventAsyncModel.BackColor = Color.Coral; Thread.Sleep(5000); MessageBox.Show("hello world"); }); }; Dispatcher.BeginInvoke(action); }
时间: 2024-10-28 11:02:12