using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { public delegate void PrintCallback(int i); static void Main(string[] args) { PrintCallback pcb = new PrintCallback(Print); for (int i = 0; i < 1000; i++) { ExcetCallback(pcb, i); Console.WriteLine("主线程;线程ID为" + System.AppDomain.GetCurrentThreadId()); } } public static void ExcetCallback(PrintCallback pcb,int i) { pcb(i); } public static void Print(int i) { Console.WriteLine("第" + i + "次执行回调;线程ID为" + System.AppDomain.GetCurrentThreadId()); Thread.Sleep(10000);//10s } } }
时间: 2024-10-26 16:38:31