Multithread and UI again ! :)

G

Guest

Hi,

I have done some coding with UI being accessed from different threads before.

But now I stuck. Need your help guys! :)

My application run not the form but some ApplicationContext class (in
function Main - Application.Run(new MyAppContext());)

That class creates 2 children. Model1 and Model2. Model1 being created in
MyAppContext constructor. In a turn frmMain being created in model1's
constructor as well..

So frmMain has no problem at all..

Model2 could be created in 2 different methods of MyAppClass. They being
called from Model1. In such a case (in Model2's constructor) frmSecond being
created and shown.

When it goes to method1 - frmSecond works fine. When it is from method2 -
frmSecond popping up to the screen but white and doesnt show anything.

All the methods which access UI in frmSecond - all are through Invoke thing.
So everything still works (I can see it in debuger). But doesnt show anything
on screen :(

Please help! :)
 
D

Dmytro Lapshyn [MVP]

Hi,

Can it be that you construct the second form on a worker thread?

The Invoke method can also be tricky - make sure that the control on which
you call Invoke was created on the main UI thread.
 
G

Guest

Thanx Dmytro,

This is basically the question - how to ensure that 2nd form being created
in worker thread?

If we are talking abt a control - it is easy - whatever thread it is - you
test InvokeRequired etc.

I am trying to find similar way (abstracted solution which works in every
case) to create form.

Shall I create 2nd form in main form and pass it back to the wrapper classes?


Vlad
 
D

Dmytro Lapshyn [MVP]

Yes, creating forms explicitly on the main thread is definitely a good idea.
However, you can pass a reference around safely only if you always pay
attention to the InvokeRequired property.

--
Regards,
Dmytro Lapshyn [MVP]
http://blogs.vbcity.com/DmytroL

maxima said:
Thanx Dmytro,

This is basically the question - how to ensure that 2nd form being created
in worker thread?

If we are talking abt a control - it is easy - whatever thread it is - you
test InvokeRequired etc.

I am trying to find similar way (abstracted solution which works in every
case) to create form.

Shall I create 2nd form in main form and pass it back to the wrapper
classes?


Vlad
 

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