N
Nils Deslé
Hi all,
I've google-searched this group first, and seen a lot of questions
about UI and workerthread issues, but I couldn't find an answer to the
following question:
I have a WinForm application that, at the click of a button, starts a
long calculation (for now, using BeginInvoke and a delegate, but I'm
quite happy to do this as a Thread).
When the calculation has finished, the UI thread would really like to
know that the worker thread is done. So far, this is a standard
question. The standard answers I've seen a few times are: use the
callback, or use events.
My problem with these solutions is that they run in the workerthread,
not the UI thread, so I have to use Invoke (not that big a deal), and
I need to make sure no-one closes the app while the processing of the
result of the workerthread is taking place. Granted, not huge
problems, but I don't like this from a design point of view. The code
I want to run when the calculation is done feels like code that
should be run in the UI thread again.
If I was coding this in C++, I would have used SendMessage from the
callback or at the end of the thread's background task to put a
user-defined message on the message queue, and a handler for that
message would process it when the UI thread got it. Is there a way of
doing something similar in WinForms?
Thanks,
Nils
I've google-searched this group first, and seen a lot of questions
about UI and workerthread issues, but I couldn't find an answer to the
following question:
I have a WinForm application that, at the click of a button, starts a
long calculation (for now, using BeginInvoke and a delegate, but I'm
quite happy to do this as a Thread).
When the calculation has finished, the UI thread would really like to
know that the worker thread is done. So far, this is a standard
question. The standard answers I've seen a few times are: use the
callback, or use events.
My problem with these solutions is that they run in the workerthread,
not the UI thread, so I have to use Invoke (not that big a deal), and
I need to make sure no-one closes the app while the processing of the
result of the workerthread is taking place. Granted, not huge
problems, but I don't like this from a design point of view. The code
I want to run when the calculation is done feels like code that
should be run in the UI thread again.
If I was coding this in C++, I would have used SendMessage from the
callback or at the end of the thread's background task to put a
user-defined message on the message queue, and a handler for that
message would process it when the UI thread got it. Is there a way of
doing something similar in WinForms?
Thanks,
Nils