Home All Groups Group Topic Archive Search About

Switching to the UI Thread

Author
24 May 2006 6:47 PM
Steve
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

Author
25 May 2006 8:09 AM
Vadym Stetsyak
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
Author
25 May 2006 5:26 PM
Steve
Hi. Thanks for the reply.

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

Show quote
"Vadym Stetsyak" wrote:

> 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
Author
26 May 2006 10:32 AM
Vadym Stetsyak
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

AddThis Social Bookmark Button