Valerie,
See inline:
> I began to get System.ExecutionEngineException errors so (on the theory of
> do something different if what you're doing isn't working)
With all due respect, this is a horrible way to fix problems. Gaining
understanding of why the errors are happening, and then addressing them is
the more prudent course of action, and saves you a headache in the
long-term.
> I switched to using delegate.BeginInvoke with the appropriate EndInvoke
> and the problem disappeared.
This will not solve your problem. When you call Control.BeginInvoke,
the call to Control.Invoke is made on a threadpool thread and the call to
BeginInvoke returns immediately. So, in effect, you have a worker thread
calling BeginInvoke. The threadpool thread then takes over and calls
Control.Invoke, waiting on the return value. The delegate passed to Invoke
is then invoked on the UI thread.
If you call Delegate.BeginInvoke, then you go from your worker thread to
the threadpool thread, where the method pointed to by the delegate gets
executed. If you are accessing UI elements on this thread, you are going to
get unpredictable results.
> Is it possible to use Control.BeginInvoke with a matching EndInvoke ?
To what end do you want to use them? They just allow processing to
continue on the thread that called them, not waiting for the UI to update.
> From my reading of the documentation, it seems as though
> delegate.BeginInvoke is using a separate thread, in which case the invoked
> code is not running on the UI's thread and therefore I have not solved my
> reentrant code worries.
I'm not sure how reentrancy plays into this. Basically, call
Control.Invoke when you want processing to be done on the UI thread.
Typically, if you want to update the UI, call it, but don't do any long-term
processing in the delegate passed to Invoke.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
(E-Mail Removed)