C#中 同步方法调用异步方法不死锁的方法 async await task
//同步方法调用异步方法
public static string Test(string cName)
{
AutoResetEvent autoResetEvent = new AutoResetEvent(false);
ThreadPool.QueueUserWorkItem(async (str) =>
{
var custom = cusService.SelectOne(c => c.CUSTOM_NAME == cName).GetAwaiter().GetResult();
autoResetEvent.Set(); // 工作完成后设置信号
}
var b = autoResetEvent.WaitOne(); // 等待信号
}

浙公网安备 33010602011771号