C# thread.sleep的作用
时间: 2023-08-14 07:03:04 浏览: 270
C#中的Thread.Sleep()方法用于使线程挂起一段时间。它的作用是让当前线程暂停执行一段时间,以便给其他线程或进程使用CPU资源的机会。\[1\]当调用Thread.Sleep(1000)时,表示当前线程会被挂起1秒钟,然后再继续执行。\[1\]如果调用Thread.Sleep(0),则表示当前线程会暂时放弃CPU,让其他已经准备好运行的、具有同等优先级的线程有机会执行。\[2\]\[3\]这个方法的作用是让当前线程让位,释放一些未用的时间片给其他线程或进程使用。
#### 引用[.reference_title]
- *1* [C# 理解Thread.Sleep()方法](https://blog.csdn.net/yjpfinui/article/details/121669983)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [C# 延迟Task.Delay()和Thread.Sleep() 学习](https://blog.csdn.net/weixin_42009898/article/details/118912633)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [解决C#中Thread.Sleep()的作用及用法](https://blog.csdn.net/mgtts/article/details/83740123)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文