The GUI thread is an STA thread. A STA thread has an obligation to
responsively process its message pump. Standard wait methods in .NET
recognize this and process the threads message pump while waiting (wait
methods that don't, like WaitAll, will cause an exception when executed on an
STA thread).
Given that this is a GUI thread, you shouldn't block the thread with
lock/Wait/Join as this will block the responsiveness of the UI.
Idle is raised when there's no more windows message in the current GUI
thread's message queue. It's an indication that the GUI thread may not be
doing anything. If you want to take the opportunity to do something, then I
would spawn a background thread to do the work. If you need to communicate
something back to the GUI then I would recommend using a BackgroundWorker
object.

Signature
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#
> I suppose the non-reentrant code could be moved into a new thread with
> a queue. This doesn't solve the general problem that the GUI can
[quoted text clipped - 55 lines]
> >
> > - Show quoted text -
jaket - 07 Nov 2007 19:53 GMT
Peter,
OnIdle is used to purposely slow updates to the GUI. Computations are
happening on a separate thread. Invoking onto the GUI thread from the
computation thread would not be feasable because the computations
sometimes happen too fast for the user's eye. Instead, the results
are written to a mailbox and the GUI checks the mailbox during Idle
time and updates. The locks are not held by either thread for long.
I don't understand how locks can be avoided in a multi-threaded
application, especially where data must be shared between the threads?
Thanks for your input, Jake
On Nov 7, 7:09 am, Peter Ritchie [C# MVP] <PRS...@newsgroups.nospam>
wrote:
> The GUI thread is an STA thread. A STA thread has an obligation to
> responsively process its message pump. Standard wait methods in .NET
[quoted text clipped - 81 lines]
>
> - Show quoted text -