Threading question

G

Guest

Is it safe to create a form in a worker thread and then have the UI thread
display and take control of it? I would think that this would not be safe.
However, .net 2.0 does not give me a cross threading error and it works
consistently with all of my forms except for one.
 
J

Jon Skeet [C# MVP]

<=?Utf-8?B?U2NvdHQgU2ltb25z?=
Is it safe to create a form in a worker thread and then have the UI thread
display and take control of it?
No.

I would think that this would not be safe.
However, .net 2.0 does not give me a cross threading error and it works
consistently with all of my forms except for one.

I'm surprised that it's not giving you an error, but no, it's not safe.
Always create GUI elements on the same thread you'll be touching them
on.
 
W

Willy Denoyette [MVP]

Scott Simons said:
Is it safe to create a form in a worker thread and then have the UI thread
display and take control of it? I would think that this would not be
safe.
However, .net 2.0 does not give me a cross threading error and it works
consistently with all of my forms except for one.

Cross-threading probes are only active in debug mode.

Willy.
 

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