C#中 同步方法调用异步方法不死锁的方法 async await task

 

1
2
3
4
5
6
7
8
9
10
11
12
13
//同步方法调用异步方法
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(); // 等待信号
 
}

  

posted @   iDEAAM  阅读(78)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
历史上的今天:
2017-01-09 RabbitMQ 消费端 Client CPU 100%的解决办法
2016-01-09 How to set JAVA environment variables in Linux or CentOS
2016-01-09 How To Setup Apache Hadoop On CentOS
2013-01-09 结合IIS 7、ARR与Velocity建设高性能的大型网站 -摘自网络
2013-01-09 IIS request filtering woes with ARR(Application Request Routing) -摘自网络
2013-01-09 Configuring SharePoint 2010 and ADFS v2 End to End-摘自网络
点击右上角即可分享
微信分享提示