M
MarkR
Hello:
I would like to know the best way to spend idle cycles while waiting for a
thread to complete. I've seen numerous conversations on this group about how
unnatural Application.DoEvents() is, but can't find a good recommendation on
what I *should* do.
<Background>
I have inherited a C# state-machine application: i.e. Step 2 begins when
Step 1 is completed; Step 3 when Step 2 completes, etc. The code is
implemented within one controller function, rather than being event-based,
that looks something like:
Controller()
{
BeginInvoke(ProducerThread);
DisplayPageSynchronous(Page1);
int result = DisplayPageSynchronous(Page2);
DisplayPageSynchronous((result == 1 ? Page3 : Page4));
...
}
Page2 is a thumbnail view of the data the ProducerThread produces. In the
legacy codebase, Page2 blocked with a Monitor.Enter call; I would like to
add either progressive display of the thumbnails or a simple progress
indicator.
Since, unfortunately, Page2 is displayed synchronously, I need its message
pump to keep running while it waits for the producer to complete, which
really sounds like a job for a while() loop with a DoEvents/Sleep pair
inside it. But the wisdom of this group is to avoid such a call.
Thus, my question: What is the best practice for waiting for a thread to
finish? Am I missing something I could do with, e.g. the AutoResetEvent or
Monitor.Pulse?
Thank you for any and all help,
/m
I would like to know the best way to spend idle cycles while waiting for a
thread to complete. I've seen numerous conversations on this group about how
unnatural Application.DoEvents() is, but can't find a good recommendation on
what I *should* do.
<Background>
I have inherited a C# state-machine application: i.e. Step 2 begins when
Step 1 is completed; Step 3 when Step 2 completes, etc. The code is
implemented within one controller function, rather than being event-based,
that looks something like:
Controller()
{
BeginInvoke(ProducerThread);
DisplayPageSynchronous(Page1);
int result = DisplayPageSynchronous(Page2);
DisplayPageSynchronous((result == 1 ? Page3 : Page4));
...
}
Page2 is a thumbnail view of the data the ProducerThread produces. In the
legacy codebase, Page2 blocked with a Monitor.Enter call; I would like to
add either progressive display of the thumbnails or a simple progress
indicator.
Since, unfortunately, Page2 is displayed synchronously, I need its message
pump to keep running while it waits for the producer to complete, which
really sounds like a job for a while() loop with a DoEvents/Sleep pair
inside it. But the wisdom of this group is to avoid such a call.
Thus, my question: What is the best practice for waiting for a thread to
finish? Am I missing something I could do with, e.g. the AutoResetEvent or
Monitor.Pulse?
Thank you for any and all help,
/m