using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
//暂停线程
namespace Recipe2
{
class Program
{
static void Main(string[] args)
{
Thread t = new Thread(PrintNumbersWithDelay);
t.Start();
PrintNumbers();
Console.ReadKey();
}
static void PrintNumbers()
{
Console.WriteLine("Starting");
for (int i = 1; i < 10; i++)
{
Console.WriteLine(i);
}
}
static void PrintNumbersWithDelay()
{
Console.WriteLine("starting");
for (int i = 1; i < 10; i++)
{
//线程挂起的制定时间
Thread.Sleep(TimeSpan.FromSeconds(2));//线程处于休眠状态 会占用尽可能少的CPU时间
Console.WriteLine(i);
}
}
}
}
转载于:https://www.cnblogs.com/tsh292278/p/9238200.html