In my application, I created a thread that relies on an object Bitmap, and when it is executed, it calls form.Invoke(form.Refresh), which draws a bitmap in the main form. (This formis a link to the main form of my application.)
Problem . I noticed that if I close the form while another thread is waiting for a callback message from the user interface thread (due to a call Invoke), the thread will wait indefinitely (?) And essentially get stuck preventing the application from closing.
Using BeginInvokedoes not make sense in my program, because the time required to update the form should be taken into account in the work of the stream.
Q: What would be the best way to prevent this?
Edit: I read in some places that this is a bad idea, but it seems to me that the only way to handle this is to call Thread.Abort(). I cannot close the stream using a flag or something like that, as it just got stuck in the call Invoke.
Edit 2: To understand what I'm looking for, this is a way to tell the worker thread that it should stop waiting for the callback Invokeand continue.
source
share