Re: Question on Progress dialog
"David Wilkinson" <no-reply@effisols.com> wrote in message
news:%234Gswf4XIHA.1188@TK2MSFTNGP04.phx.gbl...
I don't see any real difference between a callback and the thread function
checking a bool directly. The callback will run in the context of the
worker thread, and to find out what to tell the thread function it has to
do something like check a bool anyway. Either way, the thread function has
to stop what it is doing.
There are really 2 situations we are talking about. The first is when the
Cancel button notification generated by the Progress Dialog is handled by
the worker thread. In that case, setting the bool is the simplest possible
way, and the alternative of a callback adds no value, as you say.
The second is when the Cancel button notification is handled by the window
class, which perhaps created both the worker thread and the progress dialog
in the first place. This allows additional flexibility in the handler. In
addition to setting the bool to abort the worker thread, it can also
manipulate other UI such as setting the text within the Progress Dialog to
notify the user that the Cancelling might take awhile, and to do whatever
else. Clearly, this second case can't be triggered by setting a bool; it
requires a callback or PostMessage().
Now, look back at the two cases and see which alternative can be used in
both of them: you got it, only the callback can. That's why I recommend a
callback.
If you like to live dangerously, you can also use the return value of a
SendMessage() to indicate to the worker thread that it should stop.
I don't see how this would work. When would the worker thread ever send a
message to the progress dialog? It makes no sense.
-- David