Skip to content

Commit

Permalink
Eliminate internal use of "WaitForResult()".
Browse files Browse the repository at this point in the history
Addresses #21. As noted in previous commits, "WaitForResult()" can cause
deadlocks whenever there's a synchronization context (which happens in
WPF, WinForms, and ASP.Net, basically, anywhere but the console.) This
eliminates the deadlock issue when using the legacy synchronous methods.
  • Loading branch information
atheken committed Apr 15, 2015
1 parent 4cd2b7d commit 58baa59
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/Postmark.PCL.Tests/AdminClientSenderSignatureTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void Cleanup()
{
try
{
var signatures = _adminClient.GetSenderSignaturesAsync().WaitForResult();
var signatures = Task.Run(async () => await _adminClient.GetSenderSignaturesAsync()).Result;
var pendingDeletes = new List<Task>();
foreach (var f in signatures.SenderSignatures)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Postmark.PCL.Tests/AdminClientServersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected override async Task SetupAsync()
[TearDown]
public void Cleanup()
{
var servers = _adminClient.GetServersAsync().WaitForResult();
var servers = Task.Run(async () => await _adminClient.GetServersAsync()).Result;
var pendingDeletes = new List<Task>();
foreach (var server in servers.Servers)
{
Expand Down
78 changes: 39 additions & 39 deletions src/Postmark.PCL/LegacyPortableClientExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,203 +307,203 @@ public static InboundMessageDetail EndGetInboundMessageDetail(this PostmarkClien

public static PostmarkResponse SendMessage(this PostmarkClient client, string from, string to, string subject, string body)
{
return client.SendMessageAsync(from, to, subject, body).WaitForResult();
return Task.Run(async () => await client.SendMessageAsync(from, to, subject, body)).Result;
}

public static PostmarkResponse SendMessage(this PostmarkClient client, PostmarkMessage message)
{
return client.SendMessageAsync(message).WaitForResult();
return Task.Run(async () => await client.SendMessageAsync(message)).Result;
}

public static IEnumerable<PostmarkResponse> SendMessages(this PostmarkClient client, params PostmarkMessage[] messages)
{
return client.SendMessagesAsync(messages).WaitForResult();
return Task.Run(async () => await client.SendMessagesAsync(messages)).Result;
}

public static IEnumerable<PostmarkResponse> SendMessages(this PostmarkClient client, IEnumerable<PostmarkMessage> messages)
{
return client.SendMessagesAsync(messages).WaitForResult();
return Task.Run(async () => await client.SendMessagesAsync(messages)).Result;
}

public static PostmarkDeliveryStats GetDeliveryStats(this PostmarkClient client)
{
return client.GetDeliveryStatsAsync().WaitForResult();
return Task.Run(async () => await client.GetDeliveryStatsAsync()).Result;
}

public static PostmarkBounces GetBounces
(this PostmarkClient client, bool? inactive, string emailFilter,
string tag, int offset, int count)
{
return client.GetBouncesAsync(offset, count, null, inactive, emailFilter, tag).WaitForResult();
return Task.Run(async () => await client.GetBouncesAsync(offset, count, null, inactive, emailFilter, tag)).Result;
}

public static PostmarkBounces GetBounces(this PostmarkClient client,
PostmarkBounceType type, bool? inactive, string emailFilter, string tag, int offset, int count)
{
return client.GetBouncesAsync(offset, count, type, inactive, emailFilter, tag).WaitForResult();
return Task.Run(async () => await client.GetBouncesAsync(offset, count, type, inactive, emailFilter, tag)).Result;
}

public static PostmarkBounces GetBounces(this PostmarkClient client, PostmarkBounceType type, int offset, int count)
{
return client.GetBouncesAsync(offset, count, type).WaitForResult();
return Task.Run(async () => await client.GetBouncesAsync(offset, count, type)).Result;
}

public static PostmarkBounces GetBounces(this PostmarkClient client, int offset, int count)
{
return client.GetBouncesAsync(offset, count).WaitForResult();
return Task.Run(async () => await client.GetBouncesAsync(offset, count)).Result;
}

public static PostmarkBounces GetBounces
(this PostmarkClient client, PostmarkBounceType type, bool? inactive, int offset, int count)
{
return client.GetBouncesAsync(offset, count, type, inactive).WaitForResult();
return Task.Run(async () => await client.GetBouncesAsync(offset, count, type, inactive)).Result;
}

public static PostmarkBounces GetBounces(this PostmarkClient client, bool? inactive, int offset, int count)
{
return client.GetBouncesAsync(offset, count, inactive: inactive).WaitForResult();
return Task.Run(async () => await client.GetBouncesAsync(offset, count, inactive: inactive)).Result;
}

public static PostmarkBounces GetBounces(this PostmarkClient client,
PostmarkBounceType type, string emailFilter, int offset, int count)
{
return client.GetBouncesAsync(offset, count, type, emailFilter: emailFilter).WaitForResult();
return Task.Run(async () => await client.GetBouncesAsync(offset, count, type, emailFilter: emailFilter)).Result;
}

public static PostmarkBounces GetBounces(this PostmarkClient client,
string emailFilter, int offset, int count)
{
return client.GetBouncesAsync(offset, count, emailFilter: emailFilter).WaitForResult();
return Task.Run(async () => await client.GetBouncesAsync(offset, count, emailFilter: emailFilter)).Result;
}

public static PostmarkBounces GetBounces(this PostmarkClient client,
PostmarkBounceType type, string emailFilter, string tag, int offset, int count)
{
return client.GetBouncesAsync(offset, count, type, emailFilter: emailFilter, tag: tag).WaitForResult();
return Task.Run(async () => await client.GetBouncesAsync(offset, count, type, emailFilter: emailFilter, tag: tag)).Result;
}

public static PostmarkBounces GetBounces(this PostmarkClient client,
string emailFilter, string tag, int offset, int count)
{
return client.GetBouncesAsync(offset, count, emailFilter: emailFilter, tag: tag).WaitForResult();
return Task.Run(async () => await client.GetBouncesAsync(offset, count, emailFilter: emailFilter, tag: tag)).Result;
}

public static PostmarkBounces GetBounces(this PostmarkClient client,
PostmarkBounceType type, bool? inactive, string emailFilter, int offset, int count)
{
return client.GetBouncesAsync(offset, count, type,
inactive: inactive, emailFilter: emailFilter).WaitForResult();
return Task.Run(async () => await client.GetBouncesAsync(offset, count, type,
inactive: inactive, emailFilter: emailFilter)).Result;
}

public static PostmarkBounces GetBounces(this PostmarkClient client,
bool? inactive, string emailFilter, int offset, int count)
{
return client.GetBouncesAsync(offset, count,
inactive: inactive, emailFilter: emailFilter).WaitForResult();
return Task.Run(async () => await client.GetBouncesAsync(offset, count,
inactive: inactive, emailFilter: emailFilter)).Result;
}

public static PostmarkBounce GetBounce(this PostmarkClient client, string bounceId)
{
return client.GetBounceAsync(int.Parse(bounceId)).WaitForResult();
return Task.Run(async () => await client.GetBounceAsync(int.Parse(bounceId))).Result;
}

public static IEnumerable<string> GetBounceTags(this PostmarkClient client)
{
return client.GetBounceTagsAsync().WaitForResult();
return Task.Run(async () => await client.GetBounceTagsAsync()).Result;
}

public static PostmarkBounceDump GetBounceDump(this PostmarkClient client, string bounceId)
{
return client.GetBounceDumpAsync(int.Parse(bounceId)).WaitForResult();
return Task.Run(async () => await client.GetBounceDumpAsync(int.Parse(bounceId))).Result;
}

public static PostmarkBounceActivation ActivateBounce(this PostmarkClient client, string bounceId)
{
return client.ActivateBounceAsync(int.Parse(bounceId)).WaitForResult();
return Task.Run(async () => await client.ActivateBounceAsync(int.Parse(bounceId))).Result;
}

public static PostmarkOutboundMessageList GetOutboundMessages(this PostmarkClient client, int count, string subject, int offset)
{
return client.GetOutboundMessagesAsync(offset, count, subject: subject).WaitForResult();
return Task.Run(async () => await client.GetOutboundMessagesAsync(offset, count, subject: subject)).Result;
}

public static PostmarkOutboundMessageList GetOutboundMessages(this PostmarkClient client, int count, int offset, string recipient)
{
return client.GetOutboundMessagesAsync(offset, count, recipient).WaitForResult();
return Task.Run(async () => await client.GetOutboundMessagesAsync(offset, count, recipient)).Result;
}

public static PostmarkOutboundMessageList GetOutboundMessages(this PostmarkClient client, int count, int offset)
{
return client.GetOutboundMessagesAsync(offset, count).WaitForResult();
return Task.Run(async () => await client.GetOutboundMessagesAsync(offset, count)).Result;
}

public static PostmarkOutboundMessageList GetOutboundMessages(this PostmarkClient client,
string recipient, string fromemail, int count, int offset)
{
return client.GetOutboundMessagesAsync(offset, count, recipient, fromemail).WaitForResult();
return Task.Run(async () => await client.GetOutboundMessagesAsync(offset, count, recipient, fromemail)).Result;
}

public static PostmarkOutboundMessageList GetOutboundMessages(this PostmarkClient client,
string subject, int count, int offset)
{
return client.GetOutboundMessagesAsync(offset, count, subject: subject).WaitForResult();
return Task.Run(async () => await client.GetOutboundMessagesAsync(offset, count, subject: subject)).Result;
}

public static PostmarkOutboundMessageList GetOutboundMessages(this PostmarkClient client,
string fromemail, string tag, string subject, int count, int offset)
{
return client.GetOutboundMessagesAsync(offset, count,
fromemail: fromemail, subject: subject, tag: tag).WaitForResult();
return Task.Run(async () => await client.GetOutboundMessagesAsync(offset, count,
fromemail: fromemail, subject: subject, tag: tag)).Result;
}

public static PostmarkOutboundMessageList GetOutboundMessages(this PostmarkClient client,
string recipient, string fromemail, string tag, string subject, int count, int offset)
{
return client.GetOutboundMessagesAsync(offset, count, recipient, fromemail, tag, subject).WaitForResult();
return Task.Run(async () => await client.GetOutboundMessagesAsync(offset, count, recipient, fromemail, tag, subject)).Result;
}

public static OutboundMessageDetail GetOutboundMessageDetail(this PostmarkClient client, string messageID)
{
return client.GetOutboundMessageDetailsAsync(messageID).WaitForResult();
return Task.Run(async () => await client.GetOutboundMessageDetailsAsync(messageID)).Result;
}

public static MessageDump GetOutboundMessageDump(this PostmarkClient client, string messageID)
{
return client.GetOutboundMessageDumpAsync(messageID).WaitForResult();
return Task.Run(async () => await client.GetOutboundMessageDumpAsync(messageID)).Result;
}

public static PostmarkInboundMessageList GetInboundMessages(this PostmarkClient client, int count, int offset)
{
return client.GetInboundMessagesAsync(offset, count).WaitForResult();
return Task.Run(async () => await client.GetInboundMessagesAsync(offset, count)).Result;
}

public static PostmarkInboundMessageList GetInboundMessages(this PostmarkClient client,
string fromemail, int count, int offset)
{
return client.GetInboundMessagesAsync(offset, count, fromemail: fromemail).WaitForResult();
return Task.Run(async () => await client.GetInboundMessagesAsync(offset, count, fromemail: fromemail)).Result;
}

public static PostmarkInboundMessageList GetInboundMessages(this PostmarkClient client,
string fromemail, string subject, int count, int offset)
{
return client.GetInboundMessagesAsync(offset, count, fromemail: fromemail, subject: subject).WaitForResult();
return Task.Run(async () => await client.GetInboundMessagesAsync(offset, count, fromemail: fromemail, subject: subject)).Result;
}

public static PostmarkInboundMessageList GetInboundMessages(this PostmarkClient client,
string recipient, string fromemail, string subject, int count, int offset)
{
return client.GetInboundMessagesAsync(offset, count, recipient, fromemail, subject).WaitForResult();
return Task.Run(async () => await client.GetInboundMessagesAsync(offset, count, recipient, fromemail, subject)).Result;
}

public static PostmarkInboundMessageList GetInboundMessages(this PostmarkClient client,
string recipient, string fromemail, string subject, string mailboxhash, int count, int offset)
{
return client.GetInboundMessagesAsync(offset, count, recipient, fromemail, subject, mailboxhash).WaitForResult();
return Task.Run(async () => await client.GetInboundMessagesAsync(offset, count, recipient, fromemail, subject, mailboxhash)).Result;
}

public static InboundMessageDetail GetInboundMessageDetail(this PostmarkClient client, string messageID)
{
return client.GetInboundMessageDetailsAsync(messageID).WaitForResult();
return Task.Run(async () => await client.GetInboundMessageDetailsAsync(messageID)).Result;
}
}
}

0 comments on commit 58baa59

Please sign in to comment.