How to abort the thread


guys,

i using visual studio 2005, .net framework 2.0

we can abort thread using thread.abort(). got exception "thread aborted".

i use below scenario.

i have class a, in class have method m1(), inside method started thread, thread run method m2() class b.

when close form called thread.abort(), after close from, throws exception "thread aborted". after abort statement, thread still running, , inside thread updating list control values present in from.

i check other forums, , got solution have abort thread inside thread method. in forum guy said have check 1 variable, based on value can abort thread inside thread method. , can set value variable outside thread.

but not suitable me, because thread method have more number of lines , can not insert statement if variable true abort tread in many places. guys if know other way please share

 

 


regards, dp

when call thread.abort() exception (the 1 noted) thrown inside thread. worker thread should catch exception , neccessary cleanup.
however, calling thread.abort() bad thing. you have little or no control on happens in thread @ time of abort. best way stop background task signal should end. achieved in various ways. common use flag set main thread, proposed. background thread should monitor flag continuously , exit method once flag become set.

/calle 


- still confused, on higher level -


Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

job syspolicy_purge_history job fail in sqlserver 2008

Trying to register with public marketplace error with 'Get-AzureStackStampInformation'