.NET CF Asynchronous Callbacks Possible?

  • Thread starter Thread starter Michael Billard
  • Start date Start date
M

Michael Billard

The rules say that when you have a thread that wants to
modify a control on the UI thread, you need to do so on
the UI thread itself. On the desktop, you can use
Control.BeginInvoke. On the Compact Framework,
BeginInvoke does not exist, and you have to use
Control.Invoke instead. Problem is, Control.Invoke blocks
the calling thread. I would like to do the equivalent to
Control.BeginInvoke on the .NET CF. Is this possible? The
closest I've done is used a timer control on the form,
and let the calling thread set a flag, then have the
timer look for the state of that flag. Thanks.
 
Technically, when you want to invoke some code on another thread you have to
somehow pass execution to it. Normally the target thread needs to be in a
state when it can be activated, such as in waiting fora message in
GetMessage/Peekmessage. Naturally a way to pass the execution to such thread
would be via a message - precisely what you are doing with timer. More
efficient way of doing it would be to create a MessageWindow and do a
PostMessage from your other thread. PostMessage will perform required thread
switching for you. All you need to do is to stash parameters somewhere
 
Ah! This is exactly what I needed to know. I used to use
CWnd::PostMessage to accomplish my task. I had no idea
MessageWindow existed in .NET. Thanks again.
 
Back
Top