⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sample54.cs

📁 C#函数手册
💻 CS
字号:
namespace apiBook
{
	using System;
	using System.Threading;
	using System.Windows.Forms;
	public class ErrorHandler  
	{
		static int count=5;
		static AutoResetEvent autoResetEvent = new AutoResetEvent(false);
		public static void Main() 
		{
			for (int i= 0; i < 5; i++) 
			{
				ThreadPool.QueueUserWorkItem(new WaitCallback(DoPrint), i);
				//使用QueueUserWorkItem方法
			}		
			autoResetEvent.WaitOne();
			Console.WriteLine("所有线程打印完毕。");
			Console.ReadLine();
		}
		public static void DoPrint(Object obj)
		{
			int num=(int)obj;
			Console.WriteLine("当前执行第"+num+"线程。");
			if (Interlocked.Decrement(ref count) == 0)
				autoResetEvent.Set();
		}	
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -