Hi
I have 2 buttons and for each one I have a thread.By clicking on button 1, thread1 (t1) starts.I have a while loop with this condition:
while(t1.Thread State==ThreadSt ate.Running)
which should be executed untill i put the thread into sleep, but actually after 20-30 times it stopps automatically!! !
Can u guess why?
Thank u in advanced
public Program()
{
this.Size=new Size(800, 800);
b1 = new Button();
b1.Text = "Start";
b1.Location = new Point(20, 200);
b1.Click+=new EventHandler(b1 _Click);
this.Controls.A dd(b1);
t1 = new Thread(new ThreadStart(wri te));
b2 = new Button();
b2.Text = "Pause";
b2.Location = new Point(120, 200);
//b2.Click+=new EventHandler(b2 _Click);
t2 = new Thread(new ThreadStart(wri te2));
this.Controls.A dd(b2);
}
public void b1_Click(object sender, EventArgs e)
{
if (sender == b1)
{
Console.WriteLi ne(t1.ThreadSta te);
if (t1.ThreadState == ThreadState.Uns tarted)
{
t1.Start();
while (t1.ThreadState == ThreadState.Run ning)
write();
}
}
}
public static void write()
{
Console.WriteLi ne("t1 is executing");
}
I have 2 buttons and for each one I have a thread.By clicking on button 1, thread1 (t1) starts.I have a while loop with this condition:
while(t1.Thread State==ThreadSt ate.Running)
which should be executed untill i put the thread into sleep, but actually after 20-30 times it stopps automatically!! !
Can u guess why?
Thank u in advanced
public Program()
{
this.Size=new Size(800, 800);
b1 = new Button();
b1.Text = "Start";
b1.Location = new Point(20, 200);
b1.Click+=new EventHandler(b1 _Click);
this.Controls.A dd(b1);
t1 = new Thread(new ThreadStart(wri te));
b2 = new Button();
b2.Text = "Pause";
b2.Location = new Point(120, 200);
//b2.Click+=new EventHandler(b2 _Click);
t2 = new Thread(new ThreadStart(wri te2));
this.Controls.A dd(b2);
}
public void b1_Click(object sender, EventArgs e)
{
if (sender == b1)
{
Console.WriteLi ne(t1.ThreadSta te);
if (t1.ThreadState == ThreadState.Uns tarted)
{
t1.Start();
while (t1.ThreadState == ThreadState.Run ning)
write();
}
}
}
public static void write()
{
Console.WriteLi ne("t1 is executing");
}
Comment