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 termination

Thread termination

Scheduled Pinned Locked Moved C#
question
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.
  • O Offline
    O Offline
    overfreeze
    wrote on last edited by
    #1

    How do I terminate all the threads my program has started when it closes? I've tryed this code: private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (serverThread != null) serverThread.Abort(); if (clientThread != null) clientThread.Abort(); if (receiveRoutineThread != null) receiveRoutineThread.Abort(); } However, the form closes and a process with my application's name remains running. Can anyone suggest me other way of doing this?

    S D 2 Replies Last reply
    0
    • O overfreeze

      How do I terminate all the threads my program has started when it closes? I've tryed this code: private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (serverThread != null) serverThread.Abort(); if (clientThread != null) clientThread.Abort(); if (receiveRoutineThread != null) receiveRoutineThread.Abort(); } However, the form closes and a process with my application's name remains running. Can anyone suggest me other way of doing this?

      S Offline
      S Offline
      S Senthil Kumar
      wrote on last edited by
      #2

      Just set the IsBackground[^] property on each thread you create to true and you should be done. When the GUI thread shuts down, .NET forces those threads to abort. Regards Senthil _____________________________ My Blog | My Articles | My Flickr | WinMacro

      1 Reply Last reply
      0
      • O overfreeze

        How do I terminate all the threads my program has started when it closes? I've tryed this code: private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (serverThread != null) serverThread.Abort(); if (clientThread != null) clientThread.Abort(); if (receiveRoutineThread != null) receiveRoutineThread.Abort(); } However, the form closes and a process with my application's name remains running. Can anyone suggest me other way of doing this?

        D Offline
        D Offline
        Dario Solera
        wrote on last edited by
        #3

        Thread.Abort() actually aborts the thread when that operation can be performed. For example, if the thread calls a time-consuming method, the thread won't be aborted until that method returns. _____________________________________________ Tozzi is right: Gaia is getting rid of us. My Blog [ITA] - Developing ScrewTurn Wiki 1.0 Beta3

        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