1

I have a .Net40/Winforms app that runs an script in a worker thread. The script needs to create a secondary form in the UI thread because the form shouldn't terminate with the script. In Win32, I use PostMessage(mainWnd...). What's the accepted way to do this in .Net?

Max

2
  • Can you clarify "because the form shouldn't terminate with the script" please ?
    – JYL
    Jan 15, 2011 at 22:11
  • If I create the form directly in the script's thread, the form disappears when the script and it's thread is terminated.
    – Max Yaffe
    Jan 16, 2011 at 1:42

1 Answer 1

3

In the worker thread, you should use the "Invoke" method of any control to execute some code in the UI Thread.

Control.Invoke from MSDN : http://msdn.microsoft.com/en-en/library/zyzhdc6b(v=vs.80).aspx

1
  • This is correct. Control.Invoke is the same as PostMessage in Windows API.
    – Al Kepp
    Jan 16, 2011 at 7:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.