Stopping a Thread
-
Hi, I'm writing a LoadGenerator application, in which for a specific period of time certain no.of Threads are created and executes simultaneously.. That i call as RampUp threads. After sleeping for a sustain period (10secs) of time.. I want to RampDown threads, that is i want to kill the threads one by one.. I have defined an ArrayList object alThreads to maintain the Threads list.. RampUp() method
public void RampUp() { for(int i=0; i<10; i++) { Thread thread = new Thread(ExecuteSingleThread); thread.Start(); if(alThread.Contains(thread) == false) { alThreads.Add(thread); } Thread.Sleep(5000); } }
The below code kills the thread every five second.. RampDown() method
public void RampDown() { for(int i=0;i
Now the problem is after killing the first thread, all the remaining threads doesn't executes the code inside it.. Please help me.. regards, nas
-
Hi, I'm writing a LoadGenerator application, in which for a specific period of time certain no.of Threads are created and executes simultaneously.. That i call as RampUp threads. After sleeping for a sustain period (10secs) of time.. I want to RampDown threads, that is i want to kill the threads one by one.. I have defined an ArrayList object alThreads to maintain the Threads list.. RampUp() method
public void RampUp() { for(int i=0; i<10; i++) { Thread thread = new Thread(ExecuteSingleThread); thread.Start(); if(alThread.Contains(thread) == false) { alThreads.Add(thread); } Thread.Sleep(5000); } }
The below code kills the thread every five second.. RampDown() method
public void RampDown() { for(int i=0;i
Now the problem is after killing the first thread, all the remaining threads doesn't executes the code inside it.. Please help me.. regards, nas
Try looping through the threads from count-1 to 0... Note that aborting a thread throws an exception which you need to catch.
for(int i=alThreads.length-1;i >= 0; i--) { Thread thread = (Thread)alThreads[i]; if(thread.IsAlive) thread.Abort(); Thread.Sleep(5000); }
I love it when a plan comes together http://www.zonderpunt.nl[^]
-
Try looping through the threads from count-1 to 0... Note that aborting a thread throws an exception which you need to catch.
for(int i=alThreads.length-1;i >= 0; i--) { Thread thread = (Thread)alThreads[i]; if(thread.IsAlive) thread.Abort(); Thread.Sleep(5000); }
I love it when a plan comes together http://www.zonderpunt.nl[^]