Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hey guys,

I can't call a form's Show()/ShowDialog() within a thread!!!

I searched google, but i couldn't find something useful for me?

Can any one give me some guide code in order to implement this calling??

Thanks in advance
----------
some explanation:

well i'm trying to write a ' Processor Manager ' to test my skills and in here there are sometimes which in some circumstance program have to pop up some form in order to notify user the things happened in program's background, or ask permission to do something with some unwanted/violent process(es) in processor .....
every each of these performance happens in threads almost in 4 threads, as i programmed till now ...
the processes validation checking runs through program's run time in threads ....
in orther to handle this formming i create a ' FormMonitoring ' Class, which pass a form object into this, and this class queue this form and then show this form, this was my first design in order to handle what i explained before!
well there are 2 options for me :
1) change my formming strategy : i have not any other idea about this!!!??:confused:[Any idea?]
2) call forms in the thread :((
i also tried invoke the form but the result is same, the windows cames up, but the controls never create!!
any idea about this problems, this is first time i encounter with this kind of problem??:~ :doh:
the following picture is the result when i try to show a form![the result is ALMOST same when i try to invoke the form!]

A screen shot[^]
Posted
Updated 6-Mar-11 9:26am
v3
Comments
TimGameDev 1-Mar-11 12:44pm    
are there any errors?

You should never do that! ShowDialog is modal. Just think a bit of what are you trying to do.

You should re-think you design; if your explain your goal, you can get some help.

More generally, you cannot directly operate UI from non-UI thread even without modal behavior. You should use Invoke or BeginInvoke instead. This will explain all the detail: Control.Invoke() vs. Control.BeginInvoke()[^], Problem with Treeview Scanner And MD5[^].

—SA
 
Share this answer
 
You have to use Invoke.

Google is your friend: Search results for "C# ui update from thread"[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 1-Mar-11 12:53pm    
Do you think Invoke along will resolve it? This is modal behavior, I don't think it is a valid design.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900