1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 using System.Threading; 7 8 namespace ConsoleApplication1 9 { 10 class Program 11 { 12 static void Main(string[] args) 13 { 14 Thread myThread; 15 myThread = new Thread(new ThreadStart(createThread)); 16 myThread.Start(); 17 Console.WriteLine("开始线程"); 18 Thread.Sleep(10000); 19 myThread.Suspend(); 20 Console.WriteLine("挂起线程"); 21 Thread.Sleep(10000); 22 myThread.Resume(); 23 Console.WriteLine("继续线程"); 24 Console.ReadLine(); 25 } 26 public static void createThread() 27 { 28 Console.WriteLine("创建线程"); 29 Thread.Sleep(10000); 30 Console.WriteLine("线程已休眠10秒"); 31 } 32 } 33 }
时间: 2024-10-01 15:35:02