Backgroundworker form closed without cancel async?

The thread proc of your backgroundworker doesn't have to have a loop. And it doesn't have to be cancelled to finish. It simply finishes when... the proc exits!

When it finishes RunWorkerCompleted will be called.

The thread proc of your backgroundworker doesn't have to have a loop. And it doesn't have to be cancelled to finish. It simply finishes when... the proc exits!

When it finishes, RunWorkerCompleted will be called. I see a major problem in your call though: You manipulate your GUI from the background thread. This is a no-no!

All manipulations of a GUI element must be made from the thread that created the element. In your case, use ReportProgress() to delegate status information to the ProgressChanged handler that will execute it in the foreground thread. In addition, as Rewinder wrote, you can cancel the worker from FormClosing().

But if you never monitor CancellationPending from your worker proc, this is pointless.

All manipulations of a GUI element must be made from the thread that created the element. " -- can you please explain more? – Umer Mar 10 at 11:34.

If you want to be sure your backgroundworker is cancelled, you can do something like this: private void Form1_FormClosing(object sender, FormClosingEventArgs e) { myBackgroundWorker.CancelAsync(); }.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions