How do I call an asynchronous process from an asp.net hosted module using C#5 async / await?

后端 未结 2 1582
你的背包
你的背包 2021-01-16 19:15

I have a long running process that is called via a Nancy Module Get method. Rather than have the browser hang while the process runs I would like this call to be asynchronou

2条回答
  •  天涯浪人
    2021-01-16 19:33

    I am new to the async / await features of C#5 but I feel sure these are meant for just this kind of task.

    No. async/await are intended to make asynchronous programming easy within the context of a single process. They do not change the nature of HTTP communications.

    When you use await on an ASP.NET server (in the context of an HTTP request), you are returning the ASP.NET thread to the thread pool. However, ASP.NET is aware that the HTTP request has not completed, so it does not complete the response to the client (browser).

    This is by design.

    You'll need to use AJAX, SignalR, or some other solution in order to do what you want.

提交回复
热议问题