The truth is very simple.
1Thread Mthread =NULL;2 intmncnt = -;3 4 Publicfrmtest ()5 {6 InitializeComponent ();7 8Mthread =NewThread (NewThreadStart (9 DelegateTen { One while(true) A { -Thread.Sleep ( -); - Debug.WriteLine (Environment.TickCount.ToString ()); the - if(mncnt--<0) - { - Break; + } - } + //Mode 1: A if(true) at { - Stop (); - } - - //Mode 2: - if(false) in { -Thread T =NewThread (NewThreadStart ( to Delegate + { - Stop (); the })); * T.start (); $ }Panax Notoginseng })); - Mthread.start (); the } + A Private voidStop () the { + Try - { $ Mthread.abort (); $ } - Catch(Exception ex) - { the Debug.WriteLine (ex. ToString ()); - Wuyi //using mode 1 o'clock, when executed here, the following code will no longer execute the } - Wu //other Code - //... AboutDebug.WriteLine ("Stop"); $}
The first accidental "mscorlib.dll" type of exception in System.Threading.ThreadAbortException
"Test201102051346.vshost.exe" (Managed (v4.0.30319)): Loaded "C:\Windows\Microsoft.Net\assembly\GAC_MSIL\ Mscorlib.resources\v4.0_4.0.0.0_zh-hans_b77a5c561934e089\mscorlib.resources.dll "
System.Threading.ThreadAbortException: Aborting thread.
In System.Threading.Thread.AbortInternal ()
In System.Threading.Thread.Abort ()
In Test201102051346.FrmTest.Stop () position D:\Users\Wagwei\Desktop\Test201102051346\Test201102051346\FrmTest.cs: line number 62
The first accidental "Test201102051346.exe" type of exception in System.Threading.ThreadAbortException
An exception of type "System.Threading.ThreadAbortException" occurs in Test201102051346.exe, but is not processed in user code
Places to note when using threads