using System;
using System.Threading;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
bool success = false;
for (; ; ) {
string state = "this is a state.";
ThreadPool.QueueUserWorkItem((tmp)=> {
Console.WriteLine($"线程id: {Thread.CurrentThread.ManagedThreadId}");
Thread.Sleep(TimeSpan.FromSeconds(1));
if (Thread.CurrentThread.ManagedThreadId == 4) {
success = true;
}
}, state);
if (success) {
break;
}
}
Console.WriteLine("程序运行结束!");
Console.ReadKey();
}
}
}
C#客户端实现多线程运行
于 2021-04-26 22:56:56 首次发布