Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Stopping a Thread

Stopping a Thread

Scheduled Pinned Locked Moved C#
help
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nasambur
    wrote on last edited by
    #1

    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

    N 1 Reply Last reply
    0
    • N nasambur

      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

      N Offline
      N Offline
      nikneem2005
      wrote on last edited by
      #2

      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[^]

      N 1 Reply Last reply
      0
      • N nikneem2005

        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[^]

        N Offline
        N Offline
        nasambur
        wrote on last edited by
        #3

        Thanx :rose:

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups