c# - c#中Thread中suspend和sleep的区别

标签 c#

Thread.Sleep(5000);
stopwatch.Stop();
Console.WriteLine(stopwatch.ElapsedMilliseconds);
Thread.suspend(5000);
Console.WriteLine(stopwatch.ElapsedMilliseconds);

最佳答案

Sleep在单个线程上使用,它会暂停一个线程一段时间。 Whereas suspend is deprecated .

另请参阅 MSDN 中有关挂起的注释:

Do not use the Suspend and Resume methods to synchronize the activities of threads. You have no way of knowing what code a thread is executing when you suspend it. If you suspend a thread while it holds locks during a security permission evaluation, other threads in the AppDomain might be blocked. If you suspend a thread while it is executing a class constructor, other threads in the AppDomain that attempt to use that class are blocked. Deadlocks can occur very easily.

关于c# - c#中Thread中suspend和sleep的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33412962/

相关文章:

c# - 中断上传的文件锁似乎没有释放

c# - 为什么WCF代理对象无法访问全局静态对象?

c# - 将焦点设置到 .NET 用户控件...?

c# - C# 中等效的 DataInputStream 类

c# - 忘记密码 : How can I send an email to user in DotNetNuke

c# - 如何更改图片框(winform)的边框颜色?

c# - .NET Framework 4.6.1 应用程序在引用 .NET Standard 1.4 类库时出错

c# - 按钮上没有可见文字,但屏幕阅读器需要文字?

c# - 多个 Control.BeginInvoke/Invoke 调用会按顺序执行吗?

c# - 如何以编程方式执行点击事件?