Start a new thread to show form - Form never shows

  • Thread starter Thread starter Curious
  • Start date Start date
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();
}
 
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
 
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
 
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.
 
Back
Top