the simplest way for async events?

  • Thread starter Thread starter Serg
  • Start date Start date
S

Serg

How can i emulate in .net that function:
BOOL PostMessage( HWND hWnd,
UINT Msg,
WPARAM wParam,
LPARAM lParam
);I need a simple async event firing for my WindowsForm without any
callbacks. What is the simplest way for that?thanks in advSerg.
 
found myself
I think it as simple as possible:

MyDelegate d = new MyDelegate (w.method);
d.BeginInvoke (null, null);
 
Hey Serg,

Using BeginInvoke on a delegate is certainly a way of doing this. But it is not quite the same as the good ol' PostMessage since BeginInvoke will use a thread from the thread pool. If you access your form or other windows controls in the method for the delegate, make sure that you use Control.Invoke so that the controls are only accessed by their owner thread.

Regards, Jakob.
 
Serg said:
found myself
I think it as simple as possible:

MyDelegate d = new MyDelegate (w.method);
d.BeginInvoke (null, null);

That will invoke your delegate on a threadpool thread, not on the UI
thread. If you need it to be on the UI thread, use
Control.BeginInvoke(d, ...) instead.
 
Thank you Jon.
This is exactly what i need.


Jon Skeet said:
That will invoke your delegate on a threadpool thread, not on the UI
thread. If you need it to be on the UI thread, use
Control.BeginInvoke(d, ...) instead.
 
Back
Top