Yet another threading/invoking question...

  • Thread starter Thread starter MuZZy
  • Start date Start date
Please correct me if I'm wrong, but AFAIK, SendMessage doesn't do any
marshalling to the owner's thread, it sort of directly calls the
window's WndProc. It's terribly unsafe to SendMessage anything from
another thread.
 
MuZZy said:
Wow, wow hold on! What is "no longer possible in V2 of the framework" -
using Control.Invoke? Then i'll go hang on the tree, because i just
spent 10 hours in a row wrapping calls to controls using BeginInvoke.

Or did i miss something?
The 2.0 framework complains (in debug builds) about calls from non-UI
threads to control methods. This has nothing to do with
Control.Invoke/BeginInvoke (the methods wouldn't be of much use, if you
couldn't use them from any thread, would they?)

Stefan
 
No, SendMessage does marshaling for system messages(0-WM_USER), other
message types must be custom marshaled (think Control.Invoke/BeginInvoke).
The WndProc is only called directly (as a subroutine) when the SendMessage
thread is the same as the HWND owned thread (the one that created the
window), otherwise the system switches to the owning thread and puts thye
message into it's message queue where it will be picked-up by the right
thread's WndProc.
Please consult SendMessage API for more details.

Willy.
 
MuZZy said:
Wow, wow hold on! What is "no longer possible in V2 of the framework" -
using Control.Invoke? Then i'll go hang on the tree, because i just spent
10 hours in a row wrapping calls to controls using BeginInvoke.

Or did i miss something?

I'm not talking about Control.Invoke/BeginInvoke, I was talking about
accessing window properties directly from a non owning thread.

Something like:
// read Text property from non label1 owning thread
string lblTest = label1.Text;


Willy.
 
Stefan said:
The 2.0 framework complains (in debug builds) about calls from non-UI
threads to control methods.

And that's cool - i hope it will stop some brickheads in our department
from making me fix their code :)
This has nothing to do with
Control.Invoke/BeginInvoke (the methods wouldn't be of much use, if you
couldn't use them from any thread, would they?)

That's why i was surprised...
 
Back
Top