Switching to the UI Thread

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I'm customizing a COM app with .NET and my function is being called on a
worker thread. I'd like to show a dialog on the UI thread, is there a way
for me to find the UI thread and execute my code on it (new form...)?

Thanks,
Steve
 
Hello, Steve!

S> Hi,
S> I'm customizing a COM app with .NET and my function is being called on a
S> worker thread. I'd like to show a dialog on the UI thread, is there a
S> way for me to find the UI thread and execute my code on it (new
S> form...)?

If you have reference ( or know how to obtain it ) to the main form, then you can call .Invoke method in order to marshal the call to the UI thread.
( www.codeproject.com/csharp/winformthreading.asp )

If you have no UI thread, you can create it, with the same code as wizard in VS generates you, when creating WinForms project...
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
Hi. Thanks for the reply.

I do have a reference to the main window but it's an MFC window, I have its
hWnd.
 
Hello, Steve!

S> I do have a reference to the main window but it's an MFC window, I have
S> its hWnd.

Since you have window handle you can utilize SendMessage (hWnd ... ) API, and in the MFC
create appropriate message handler. This handler will show the dialog you want...
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
Back
Top