"I'm curious as to why it
sometimes works for a worker thread to update a UI
control. For instance, it could update a textbox.
Frankly, I don't know. And I don't think someone from MS will bother itself
to explain us why is this. I'm curious too. Unfortunately both ROTOR and
MONO projects, which sources we can look at don't implement WindowsForms
classes.
Perhaps the textbox isn't a native control?
It has a native controls underneath.
Additionally, the UI control is just another object. I suppose I'm
still hazy why two threads can't access the same control
if you can avoid race condition.
Actually, it serve more as a *wrapping* objects for a native windows
control. Some of the properties and methods are translated to SendMessage
calls.
I think you can use any method or property that doesn't involve the native
control from any thread and it will work as long as you make sure the usage
is thread safe.
For example MFC keeps table to map between windows handles (HWND) and
MFC-window classes. That table is kept in the thread stack and that is why
methods that need HWND cannot be called from within different thread. I have
read that one of the reason for doing that is to prevent using window
classes from another threads. Again, unless we have the source codes nobody
will tell us why it is like that in WindowsForms.
Also, if a worker thread
calls Invoke() on a control, is it merely marshalling the
call's parameters and proceed with the rest of its task or
is it waiting for the control to finish its task,
therefore opening a possibility for a deadlock?
It will definitely wait for the control to finish its task if the call is
made form another thread. Otherwise thread context switching cannot be done.
B\rgds
100