ActiveCampaign / postmark-dotnet

A .NET library for the Postmark API
http://developer.postmarkapp.com/
Other
50 stars 46 forks source link

SendMessage and SendMessageAsync have different overloads #65

Closed kfrancis closed 6 years ago

kfrancis commented 6 years ago

I have legacy sync code and I'm trying to update to use a template, but the SendMessage doesn't allow TemplatePostmarkMessage types and SendMessageAsync just spins (specifically I'm using SendMessageAsync(templateMessage).Result).

  1. Why does SendEmailWithTemplateAsync exist if it does the same thing with SendMessageAsync?
  2. Why does SendMessage not have the same overloads SendMessageAsync does?
atheken commented 6 years ago

The reason the async method "spins" is that you need to await the task before proceeding. Depending on context, this will require you to also set .ConfigureAwait(false)

var sendingTask = SendMessageAsync(templateMessage);
sendingTask.ConfigureAwait(false);//optional depending on use case
sendingTask.Wait();
//get the result of the call, remember, this can throw.
sendingtask.Result;