MessageQueue and Async / Await

前端 未结 2 955
自闭症患者
自闭症患者 2021-02-08 04:16

I only want to receive my message in a async method! and its freezing my UI

    public async void ProcessMessages()
    {
        MessageQueue MyMessageQueue = n         


        
2条回答
  •  攒了一身酷
    2021-02-08 04:58

    async does not run your code on a background thread. Your code above should have caused a compiler warning that tells you that your method will run synchronously.

    If you want to execute a method on a background thread, use TaskEx.Run:

    public void ProcessMessages()
    {
      ...
    }
    
    TaskEx.Run(() => ProcessMessages());
    

提交回复
热议问题