stopping a thread
-
Hi. I am experimenting with threading and I made the following simple program: Thread blue = new Thread(new ThreadStart(bluebegin) ); Thread yellow = new Thread(new ThreadStart(yellowbegin) ); Thread red = new Thread(new ThreadStart(redbegin) ); blue.Start(); yellow.Start(); red.Start(); .... .... public void bluebegin() { this.BackColor = Color.Blue; Thread.Sleep(2000); yellowbegin(); } public void yellowbegin() { this.BackColor = Color.Yellow; Thread.Sleep(500); redbegin(); } public void redbegin() { this.BackColor = Color.Red; Thread.Sleep(3000); bluebegin(); } I don´t know how to stop one or all threads. I have tried adding to one of the methods : blue.Abort(); but then I am told that the namespace blue could not be found. Can someone please help me? Thanks, F
-
Hi. I am experimenting with threading and I made the following simple program: Thread blue = new Thread(new ThreadStart(bluebegin) ); Thread yellow = new Thread(new ThreadStart(yellowbegin) ); Thread red = new Thread(new ThreadStart(redbegin) ); blue.Start(); yellow.Start(); red.Start(); .... .... public void bluebegin() { this.BackColor = Color.Blue; Thread.Sleep(2000); yellowbegin(); } public void yellowbegin() { this.BackColor = Color.Yellow; Thread.Sleep(500); redbegin(); } public void redbegin() { this.BackColor = Color.Red; Thread.Sleep(3000); bluebegin(); } I don´t know how to stop one or all threads. I have tried adding to one of the methods : blue.Abort(); but then I am told that the namespace blue could not be found. Can someone please help me? Thanks, F
-
Hi. I am experimenting with threading and I made the following simple program: Thread blue = new Thread(new ThreadStart(bluebegin) ); Thread yellow = new Thread(new ThreadStart(yellowbegin) ); Thread red = new Thread(new ThreadStart(redbegin) ); blue.Start(); yellow.Start(); red.Start(); .... .... public void bluebegin() { this.BackColor = Color.Blue; Thread.Sleep(2000); yellowbegin(); } public void yellowbegin() { this.BackColor = Color.Yellow; Thread.Sleep(500); redbegin(); } public void redbegin() { this.BackColor = Color.Red; Thread.Sleep(3000); bluebegin(); } I don´t know how to stop one or all threads. I have tried adding to one of the methods : blue.Abort(); but then I am told that the namespace blue could not be found. Can someone please help me? Thanks, F
public void bluebegin()
{
bool notTerminated=true;
public bool NotTerminated { get; set; }
while ( NotTerminated )
{
this.BackColor = Color.Blue;
thread.Sleep(500);
}
}That should be enough to have you figure out what to do next. -- modified at 10:10 Wednesday 19th April, 2006