Thread abortion before closing form
-
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
-
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
-
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 nowYes I'm aborting thread as I didnt find any other method for closing thread.Plz Tell how to abort properly?
Shanzay
-
Yes I'm aborting thread as I didnt find any other method for closing thread.Plz Tell how to abort properly?
Shanzay
-
Just return from the ThreadStart method! :)
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4 out now (27 May 2008)How to return and what to return plz tell clearly :(
Shanzay