I'm pretty confused as too which method is going to be the best solution for me.
I have a controller that calls a method 'PostEventEmailMessage' and inside the method I call
// do some work
var queueClient = QueueClient.CreateFromConnectionString(serviceBusConnectionString, queueName);
var sequenceToCancel = queueClient.ScheduleMessageAsync(message, postEventTimeToSendEmail);
queueClient.CloseAsync();
// do remaining work
where I'm really confused is which method below is the best to make it run synchronously or if there is a better solution all together in Asp.Net MVC? It seems like the first 2 options have deadlock issues, according to the links I'm referencing.
Should I use 1.
var sequenceToCancel = queueClient.ScheduleMessageAsync(message, postEventTimeToSendEmail).GetAwaiter().GetResult();
2.
var sequenceToCancel = queueClient.ScheduleMessageAsync(message, postEventTimeToSendEmail).Result;
3.
var sequenceToCancel = Task.Run(() => queueClient.ScheduleMessageAsync(message, postEventTimeToSendEmail)).Result;
my controller looks something like this
public ActionResult SaveSpaceEvent(Details details) {
_spaceservice.SaveSpaceEvent(details);
}
then the 'SaveSpaceEvent' method looks like this
public void SaveSpaceEvent(Details, details) {
// do some stuff
_messageService.PostEventEmailMessage(details)
// do more stuff
}
and the async queue message is being called in 'PostEventEmailMessage'