The scenario is the following:
I have a function allowing the user to send messages to other users. The sending of a message is done in an asynchronous action:
public async Task<IActionResult> CreateMessage
This action does the following in order:
The last two lines in the action is the following:
_notificationHubProxy.SendNotification(messageToReturnResource.SenderName, messageToPush, recipientId);
return Ok(messageToReturnResource);
SendNotification is asynchronous but I choose to not await it to avoid UI-locks caused by the waiting of the request to finish. At the moment all this seems to work fine.
My question is really the following: is this okey (i.e. to not await), or is this an example of writing bad code which will cause problems when I have many clients using the application?
Regards
There are a few problems with fire-and-forget on ASP.NET (both Core and Classic):
The use cases for Fire and Forget on ASP.NET are much rarer than most people think. Not only do you have to be OK with silently swallowing errors, but you also have to be OK with occasionally losing that work.
I choose to not await it to avoid UI-locks caused by the waiting of the request to finish.
That sounds like a UI problem that should be solved by a UI solution.
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