Setting a form.Owner from a different thread in .net 2.0

J

Jeronimo Bertran

Hello,

I have an splash window application that creates a form from one thread
(call it formSplash) and runs it and later on a differnt thread a new form
(mainForm) is created and I want to make mainForm the owner of formSplash
so that it appears behind.

Using VS2003 I was able to do this by simply setting the Owner member of
the splashForm from the mainForm thread. With .net 2.0 I get the following
error:

Cross-thread operation not valid: Control 'formSplash' accessed from a
thread other than the thread it was created on.

I then used formSplash.Invoke to call a method that would set the variable
and passed it the mainForm as a parameter but when I assign it to the Owner
member variable I now get the following error:

Cross-thread operation not valid: Control 'mainForm' accessed from a thread
other than the thread it was created on.


I hope I was able to explain the problem correctly...

Thanks

Jeronimo
 
J

Jeffrey Tan[MSFT]

Hi Jeronimo,

Thanks for your post.

Yes, this is a known and by design issue. Our product team added this check
to protect programmers from making calls on UI controls from a non-UI
thread. However, we can disable this behavior with adding the following
calling in Form's construnctor:
Control.CheckForIllegalCrossThreadCalls = false;

For more information, please refer to the link below:
"Bug Details: Cross threaded exception in Debug mode"
http://lab.msdn.microsoft.com/ProductFeedback/viewFeedback.aspx?feedbackid=3
fa5a7c0-33c7-4135-9253-d751f706ae8d

Hope this helps

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi Jeronimo,

Does my reply make sense to you? Is your problem resolved? Please feel free
to tell me, thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top