Start a new thread to show form - Form never shows

C

Curious

When I click on the OK button on the main form, I close the main form
and then start a new thread to show another form. My code is below.
But the other form never shows up! Anything wrong with my code?

private void btOK_Click(object sender, EventArgs e)
{
try
{
this.Close();

Thread sf = new Thread(new ThreadStart(ShowForm));
sf.Start();

}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}

}

private void ShowForm()
{
TestForm tf = new TestForm();
tf.Show();
}
 
S

Scott M.

Curious said:
When I click on the OK button on the main form, I close the main form
and then start a new thread to show another form. My code is below.
But the other form never shows up! Anything wrong with my code?

private void btOK_Click(object sender, EventArgs e)
{
try
{
this.Close();

Thread sf = new Thread(new ThreadStart(ShowForm));
sf.Start();

}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}

}

private void ShowForm()
{
TestForm tf = new TestForm();
tf.Show();
}

If you are closing the main form, why start a new thread for a second form?

-Scott
 
F

Family Tree Mike

Curious said:
When I click on the OK button on the main form, I close the main form
and then start a new thread to show another form. My code is below.
But the other form never shows up! Anything wrong with my code?

private void btOK_Click(object sender, EventArgs e)
{
try
{
this.Close();

Thread sf = new Thread(new ThreadStart(ShowForm));
sf.Start();

}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}

}

private void ShowForm()
{
TestForm tf = new TestForm();
tf.Show();
}
.

I believe that you have effectively killed the message loop, so that no
windows messages are being sent to draw the form. Someone will chime in with
more details on that that I can offer.

An option would be to call Application.Run(new TestForm()) in your
ShowForm() methood.

Mike
 
C

Curious

If you are closing the main form, why start a new thread for a second form?

-Scott- Hide quoted text -

- Show quoted text -

You're right. I don't need a new thread.
 

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