Places to note when using threads

Source: Internet
Author: User
Tags mscorlib

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.