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. Thread problem

Thread problem

Scheduled Pinned Locked Moved C#
questionhelp
4 Posts 4 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.
  • A Offline
    A Offline
    azusakt
    wrote on last edited by
    #1

    Hi, I want to ask 1. what is the good instructions to close the Thread? set it to null or using Thread.Abort()? 2. how about aborting the thread? 3. how can I prevent if the thread is in Sleep state, can I also close it or abort it?? I have one class which contains one Thread, if I wnat to re-create a new class, like this.Threadclass = new BThreadClass(); should I close the Thread inside the class again? Thanks for help

    C 1 Reply Last reply
    0
    • A azusakt

      Hi, I want to ask 1. what is the good instructions to close the Thread? set it to null or using Thread.Abort()? 2. how about aborting the thread? 3. how can I prevent if the thread is in Sleep state, can I also close it or abort it?? I have one class which contains one Thread, if I wnat to re-create a new class, like this.Threadclass = new BThreadClass(); should I close the Thread inside the class again? Thanks for help

      C Offline
      C Offline
      Corinna John
      wrote on last edited by
      #2

      Setting the thread to null does not stop it ;) If you don't want to use Thread.Abort, use a bool variable: private void MyThreadMethod(){ isRunning = true; while(isRunning){ doSomething(); Sleep(xyz); } } Set isRunning=false, and the thread stops without an exception.

      J 1 Reply Last reply
      0
      • C Corinna John

        Setting the thread to null does not stop it ;) If you don't want to use Thread.Abort, use a bool variable: private void MyThreadMethod(){ isRunning = true; while(isRunning){ doSomething(); Sleep(xyz); } } Set isRunning=false, and the thread stops without an exception.

        J Offline
        J Offline
        Jan Vercauteren
        wrote on last edited by
        #3

        this is true, you have to let a thread stop itself, thread.abord() just raises an exception in the thread to stop it. Problem with this exception is that you cant handle it and the entire app will stop. www.agilis.be

        H 1 Reply Last reply
        0
        • J Jan Vercauteren

          this is true, you have to let a thread stop itself, thread.abord() just raises an exception in the thread to stop it. Problem with this exception is that you cant handle it and the entire app will stop. www.agilis.be

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          You can handle it with the AppDomain.UnhandledException or, if applicable, Application.ThreadException event.

          Microsoft MVP, Visual C# My Articles

          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