Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does an asynchronous task with no return need to finish before an ASP.NET request can end

I'm developing a auction trading system for trading vehicles within the company I work for.

Traders can set alerts and whenever a new listing is submitted I want to use the details of the new listing to search through everybody's alerts for matches, but this shouldn't be time a trader should be waiting to get back confirmation of their successful listing so I want to run it in the background.

My question is, if I mark the function async and not worry about the return will the ASP.NET MVC framework still want to wait for the asynchronous function to end before ending the request?

I know I probably could test this but I'm not sure how, I haven't got too deep in my async books yet.

Thanks.

like image 806
addy_wils Avatar asked Mar 15 '14 16:03

addy_wils


People also ask

What happens if you don't await an async method C#?

The call to the async method starts an asynchronous task. However, because no Await operator is applied, the program continues without waiting for the task to complete.

Is an async method that returns Task a return keyword must not be followed by an object?

DoSomething()' is an async method that returns 'Task', a return keyword must not be followed by an object expression. Did you intend to return 'Task<T>'?

Which is the recommended way to wait for an async method to complete?

No problem, just make a loop and call this function with an await: [code] for (int i = pendingList. Count - 1; i >= 0; i--)

Is an async method that returns Task?

Async methods can have the following return types: Task, for an async method that performs an operation but returns no value. Task<TResult>, for an async method that returns a value. void , for an event handler.


1 Answers

In ASP.NET you're limited to the boundaries of a given HTTP request/response. You can and should use async/await inside your ASP.NET MVC/Web API controller methods (as described here), this improves the scalability of your web app.

However, it doesn't change the fact the client-side web browser has sent an HTTP request and is still waiting for the HTTP response. Normally, all of the the async operation started by an async controller method should have become completed, before the response is sent to the client.

If you need to span a long-running server-side operation across the boundaries of a single HTTP request, here is a related answer. If your client-side logic requires high frequency updates from the server, Microsoft has SignalR for that.

like image 104
noseratio Avatar answered Nov 03 '22 10:11

noseratio