如何阻止后台工作人员在表单的闭幕式上工作?
Invoke((Action) (...));
HandleClosingEvent
bgWorker.CancelAsync()
ObjectDisposedException
Invoke(...)
HandleClosingEvent
public Form1() { InitializeComponent(); Closing += HandleClosingEvent; this.bgWorker.RunWorkerAsync(); } private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { while (!this.bgWorker.CancellationPending) { Invoke((Action) (() => { this.textBox1.Text = Environment.TickCount.ToString(); })); } } private void HandleClosingEvent(object sender, CancelEventArgs e) { this.bgWorker.CancelAsync(); /////// while (this.bgWorker.CancellationPending) {} // deadlock }
梵蒂冈之花
犯罪嫌疑人X