Multiple Forms Hiding and closing

B

Bob

Hi,
I have an app that requires 4 child forms each created on a separate thread.
Each form holds a 3rd Party Phone answering control.
The control will only answer the phone if the form has been displayed.
Instantiating the form is not enough.
The only way I have been able to display the form(s) is myForm.ShowDialog();
myForm.Show() does nothing. (Code snippet below.)
So...
I can't issue a hide instruction as the calling code is waiting for the
dialog to return.
I thought maybe a hide in the form's constructor but no, that's ignored as
well.
Any ideas on how hide these would be appreciated.
thanks
Bob
***In MAIN FORM'S CTOR****
ThreadStart ts1 = new ThreadStart(MakeLine1);

Thread t1 = new Thread(ts1);

t1.SetApartmentState(ApartmentState.STA);

t1.Start();

**************************

private void MakeLine1()

{

frmAnswer f1 = new frmAnswer(1);

f1.ShowDialog();

}
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Bob said:
Hi,
I have an app that requires 4 child forms each created on a separate
thread.

Not possible, they must be created from the UI thread

Each form holds a 3rd Party Phone answering control.
The control will only answer the phone if the form has been displayed.
Instantiating the form is not enough.
The only way I have been able to display the form(s) is
myForm.ShowDialog();
myForm.Show() does nothing. (Code snippet below.)

Of course, you have to call Show(), now what if you create the form, set it
as minimized and set that does not appear in the task bar?

Did you tried to make your form transparent?

why dont y ou want to show the forms in the first pkace?
 
B

Bruce Wood

Bob said:
Hi,
I have an app that requires 4 child forms each created on a separate thread.
Each form holds a 3rd Party Phone answering control.
The control will only answer the phone if the form has been displayed.
Instantiating the form is not enough.
The only way I have been able to display the form(s) is myForm.ShowDialog();
myForm.Show() does nothing. (Code snippet below.)
So...
I can't issue a hide instruction as the calling code is waiting for the
dialog to return.
I thought maybe a hide in the form's constructor but no, that's ignored as
well.
Any ideas on how hide these would be appreciated.
thanks
Bob
***In MAIN FORM'S CTOR****
ThreadStart ts1 = new ThreadStart(MakeLine1);

Thread t1 = new Thread(ts1);

t1.SetApartmentState(ApartmentState.STA);

t1.Start();

**************************

private void MakeLine1()

{

frmAnswer f1 = new frmAnswer(1);

f1.ShowDialog();

}

As Ignacio pointed out, you can't create / display forms using other
threads. You can create / display forms only from the UI thread.

As well, you problem is likely that you created the frmAnswer form, did
a .Show(), and then your thread continues executing... and terminates,
so the frmAnswer form is then closed and disposed.

I believe that a good start toward resolving this problem would be to
reverse the relationship between the thread and the form: create the
frmAnswer form, and have that in turn create the background thread. So,
the form owns the thread, not the other way around.
 

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