简体   繁体   中英

Thread.Resume Obsolete or decprecated: How to resume a suspended thread without using System.Threading.Thread.Resume?

Here is how I resume a suspended thread.

  if SerialThread.ThreadState = ThreadState.Suspended then
    SerialThread.Resume;

Although the above code doesn't raise compiler error or syntax error, it does however raise warning as follows;

TSerialIndicator.pas(77,18): warning PW3: Obsolete: "System.Threading.Thread.Resume has been deprecated. Please use other classes in System.Threading, such as Monitor, Mutex, Event, and Semaphore, to synchronize Threads or protect resources.

So, what is the proper way in .NET to resume a suspended thread?

AutoResetEvent非常适合“挂起”线程,您的线程代码仅调用event.Wait,直到调用者调用event.Set()中断了等待,直到有事为止。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM