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 abortion before closing form

Thread abortion before closing form

Scheduled Pinned Locked Moved C#
tutorial
5 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.
  • D Offline
    D Offline
    DeepOceans
    wrote on last edited by
    #1

    Hi, I am using multiple threads in my application and want to abort or close all threads when Exit application or click on Disconnect.But in my case as shown in code, thread status remain alive even I m aborting.Can any1 give me code snippset that how to abort thread successfully :

             try
                    {
                        // Client_Login clog = new Client_Login();
                        if (clog.clnt_th.IsAlive)
                        {
                            clog.clnt_th.Abort();//clog is other class object
                            clog.clnt_th.Join(1);
                        }
                         if (ClPb.thvidinfo.IsAlive)
                        {
                           ClPb.thvidinfo.Abort();//ClPb is other class object
                           ClPb.thvidinfo.Join(2);
    
                        }
                        if (ClPb.thvideofile.IsAlive)
                        {
                            ClPb.thvideofile.Abort();
                            ClPb.thvideofile.Join(3);
                        }
                       
                        if (thvideo.IsAlive)
                        {
                            thvideo.Abort();
                            thvideo.Join(4);
                        }
    
                    }
                    catch(System.Threading.ThreadAbortException thexp)
                    {
                        MessageBox.Show("Time worker thread was aborted: " + DateTime.Now.ToString(),thexp.Message );
    
                    }
    

    thvideo is parent thread and thvideofile and thvidinfo is its child threads.

    Shanzay

    L 1 Reply Last reply
    0
    • D DeepOceans

      Hi, I am using multiple threads in my application and want to abort or close all threads when Exit application or click on Disconnect.But in my case as shown in code, thread status remain alive even I m aborting.Can any1 give me code snippset that how to abort thread successfully :

               try
                      {
                          // Client_Login clog = new Client_Login();
                          if (clog.clnt_th.IsAlive)
                          {
                              clog.clnt_th.Abort();//clog is other class object
                              clog.clnt_th.Join(1);
                          }
                           if (ClPb.thvidinfo.IsAlive)
                          {
                             ClPb.thvidinfo.Abort();//ClPb is other class object
                             ClPb.thvidinfo.Join(2);
      
                          }
                          if (ClPb.thvideofile.IsAlive)
                          {
                              ClPb.thvideofile.Abort();
                              ClPb.thvideofile.Join(3);
                          }
                         
                          if (thvideo.IsAlive)
                          {
                              thvideo.Abort();
                              thvideo.Join(4);
                          }
      
                      }
                      catch(System.Threading.ThreadAbortException thexp)
                      {
                          MessageBox.Show("Time worker thread was aborted: " + DateTime.Now.ToString(),thexp.Message );
      
                      }
      

      thvideo is parent thread and thvideofile and thvidinfo is its child threads.

      Shanzay

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      You are aborting the thread, so it will throw a ThreadAbortException. Rather exit the thread properly.

      xacc.ide - now with TabsToSpaces support
      IronScheme - 1.0 alpha 3 out now

      D 1 Reply Last reply
      0
      • L leppie

        You are aborting the thread, so it will throw a ThreadAbortException. Rather exit the thread properly.

        xacc.ide - now with TabsToSpaces support
        IronScheme - 1.0 alpha 3 out now

        D Offline
        D Offline
        DeepOceans
        wrote on last edited by
        #3

        Yes I'm aborting thread as I didnt find any other method for closing thread.Plz Tell how to abort properly?

        Shanzay

        L 1 Reply Last reply
        0
        • D DeepOceans

          Yes I'm aborting thread as I didnt find any other method for closing thread.Plz Tell how to abort properly?

          Shanzay

          L Offline
          L Offline
          leppie
          wrote on last edited by
          #4

          Just return from the ThreadStart method! :)

          xacc.ide - now with TabsToSpaces support
          IronScheme - 1.0 alpha 4 out now (27 May 2008)

          D 1 Reply Last reply
          0
          • L leppie

            Just return from the ThreadStart method! :)

            xacc.ide - now with TabsToSpaces support
            IronScheme - 1.0 alpha 4 out now (27 May 2008)

            D Offline
            D Offline
            DeepOceans
            wrote on last edited by
            #5

            How to return and what to return plz tell clearly :(

            Shanzay

            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