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

后端 未结 2 1580
你的背包
你的背包 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.

    0 讨论(0)
  • 2021-01-16 19:56

    try setting the page attribute Async="true"in the aspx page after doing that it wold look like this <%@ Page Language="C#" AutoEventWireup="true" CodeFile="XXX.aspx.cs" Inherits="xxx" Async="true" %>

    the in tcode behile file you can make the tasks and methods of type async and calll await tasks from them ...

    it might work

    0 讨论(0)
提交回复
热议问题