I have a thread that does some work in the background and passes updates to the form using Invoke, BeginInvoke methods. The stream is created after the form is displayed, so there is no problem.
The problem is how to shut down properly. My working thread has the ability to ask to exit and will soon come out after a while (miliseconds).
However, if the form is closed, the Invoke material first unfolds. I tried adding Thread.Join to the form closing event, but of course this causes a deadlock, even for BeginInvoke, since Thread.Join has since blocked BeginInvoke in this thread ...
What is the correct way to close a form and completely close a workflow?
EDIT:
base current code:
volatile bool abort; void WorkerThread() { while(!abort)DoStuffIncludingInvokesOnThisForm(); } void MyForm_FormClosing(object sender, FormClosingEventArgs e) { abort = true; workerThread.Join();
source share