Main Page | Report this Page
.NET DotNet Forum Index  »  General Discussion  »  Start a new thread to show form - Form never shows...
Page 1 of 1    

Start a new thread to show form - Form never shows...

Author Message
Curious...
Posted: Thu Oct 29, 2009 3:49 am
Guest
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();
}
 
Scott M....
Posted: Thu Oct 29, 2009 9:09 am
Guest
"Curious" <fir5tsight at (no spam) yahoo.com> wrote in message
news:c36899b0-ef05-4874-a981-5488e707c88e at (no spam) b25g2000prb.googlegroups.com...
Quote:
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...
Posted: Thu Oct 29, 2009 10:04 am
Guest
On Oct 29, 11:09 am, "Scott M." <s-... at (no spam) nospam.nospam> wrote:
Quote:
"Curious" <fir5tsi... at (no spam) yahoo.com> wrote in message

news:c36899b0-ef05-4874-a981-5488e707c88e at (no spam) b25g2000prb.googlegroups.com...





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- Hide quoted text -

- Show quoted text -

You're right. I don't need a new thread.
 
Family Tree Mike...
Posted: Thu Oct 29, 2009 10:20 am
Guest
"Curious" wrote:

Quote:
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
 
 
Page 1 of 1    
All times are GMT - 5 Hours
The time now is Mon Nov 30, 2009 10:15 am