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#
helptutorialquestion
3 Posts 3 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
    naglbitur
    wrote on last edited by
    #1

    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

    G L 2 Replies Last reply
    0
    • N naglbitur

      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

      G Offline
      G Offline
      Gammaza
      wrote on last edited by
      #2

      Try creating a click event or a button where you can abort the threads, not in their thread methods.

      1 Reply Last reply
      0
      • N naglbitur

        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

        L Offline
        L Offline
        LongRange Shooter
        wrote on last edited by
        #3

        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

        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