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.
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.
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>'?
No problem, just make a loop and call this function with an await: [code] for (int i = pendingList. Count - 1; i >= 0; i--)
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With