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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. how to kill a thread gracfully

how to kill a thread gracfully

Scheduled Pinned Locked Moved C#
csharptutorialquestion
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.
  • P Offline
    P Offline
    Parshant Verma
    wrote on last edited by
    #1

    Hi how can i kil thread gracefully in c#1.1

    G L 2 Replies Last reply
    0
    • P Parshant Verma

      Hi how can i kil thread gracefully in c#1.1

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

      The most graceful way is to tell the thread to stop on it's own. If the thread is running an instance method of a class, you could change a proeprty in the class to flag that it's time to stop. Otherwise there is a special exception (don't recall what it's called right now) that you can raise in the thead, that you can initiate from outside the thread and catch inside the thread. That gives the thread a chance to clean up whatever it needs before turning in. -- modified at 9:11 Sunday 8th October, 2006 I was just reading about Monitors, and stumbled upon the Exception that is used to interrupt a thread. The exception is ThreadInterruptedException, and is created with the Interrupt method of the Thread class.

      --- b { font-weight: normal; }

      1 Reply Last reply
      0
      • P Parshant Verma

        Hi how can i kil thread gracefully in c#1.1

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Use something like a volatile bool quit, set it to true and periodically check if it's true in your thread. regards

        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