在本文中,我将解释如何通过在.NET Framework中使用Thread.sleep方法暂停线程。
暂停线程是多线程应用中的重要概念。
Sleep方法在线程类Thread中找到。
Thread.Sleep方法可用于暂停线程一个固定时间段。
Thread.Sleep方法是在毫秒内接收值。
在C#中暂停线程示例
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; namespace multi { class Program { static void Main(string[] args) { Thread th = new Thread(WriteY); th.Start(); for (int i = 0; i <= 10; i++) { Console.WriteLine("Hello"); Thread.Sleep(1000); } } private static void WriteY() { for (int i = 0; i <= 9; i++) { Console.WriteLine("world"); Thread.Sleep(500); } } } }
C# Thread.Sleep方法语法
Thread.Sleep(Time in millisecond);
日期:2020-04-11 23:03:48 来源:oir作者:oir