Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using Await and async in ASP.NET app
Message
From
13/04/2016 10:17:46
 
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01634709
Message ID:
01634741
Views:
31
>>>Hi,
>>>
>>>One of the features of my ASP.NET application is where a user enters some information and on Submit a stored procedure is called, which adds record(s) to the database. Then a method is called which sends email(s) to a distribution list. Sometimes the Email method/routine takes quite a bit of time (up to a minute) and the user has to wait for the Acknowledgement of submit. Recently I read a couple of on-line articles on Task Parallel Library and on await and async. I am still not 100% sure I understand these concepts (but it never in the past stopped me from implementing things I don't understand :)). So I am thinking of converting the method that sends emails to the "await" and "async" type method so that the user will get to the acknowledgement page faster, while the emails are being sent on another thread.
>>>
>>>Does it make sense?
>>
>>To be clear: Do you want to simply notify the user that the request to send an email has been received - or that the email was successfully sent ?
>>
>>If the former then you could just use a call to an async task without the await. In essence :
public bool EmailSendRequest(Email e)
>>        {
>>            SendEmail(e);
>>            return true;
>>        }
>>
>> public async Task SendEmail(Email e)
>>        {
>>            //Do whatever to send etc.
>>        }
If you wanted to notify the user on the actual success/failure of the send you could use something like SignalR to push to the user later....
>
>Therefore it looks like "await" is not necessary.

If you wanted code to run after the SendEmail() task completed you could use await and add that code after the call. But to use 'await' the enclosing method must be an async task.....

> I am not at all familiar with SignalR, will Google it.

In simple terms SignalR would allow your client side to listen for messages sent by the server so the browser could be sent a notification if the email send failed



>Thank you.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform