Skip to content

Commit 687621f

Browse files
committed
Use await Task.Run instead of ContinueWith as the latter does not wait
1 parent b33a300 commit 687621f

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Signal-Windows.Lib/OutgoingMessages.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ public async Task HandleOutgoingMessages()
161161
Logger.LogDebug("HandleOutgoingMessages()");
162162
try
163163
{
164-
await CreatePipeTask.ContinueWith(async _ =>
164+
await CreatePipeTask;
165+
await Task.Run(async () =>
165166
{
166167
var pipe = await CreatePipeTask;
167168
var messageSender = new SignalServiceMessageSender(Token, LibUtils.ServiceConfiguration, Store.Username, Store.Password, (int)Store.DeviceId, new Store(), pipe, null, LibUtils.USER_AGENT);
@@ -212,9 +213,13 @@ await CreatePipeTask.ContinueWith(async _ =>
212213
}
213214
await Handle.HandleMessageSentLocked(sendable);
214215
}
215-
}, TaskContinuationOptions.RunContinuationsAsynchronously);
216+
Logger.LogInformation("HandleOutgoingMessages() stopping: cancellation was requested");
217+
});
218+
}
219+
catch (OperationCanceledException)
220+
{
221+
Logger.LogInformation("HandleOutgoingMessages() stopping: cancellation was requested (OperationCancelledException)");
216222
}
217-
catch (OperationCanceledException) { }
218223
catch (Exception e)
219224
{
220225
Logger.LogError($"HandleOutgoingMessages() failed: {e.Message}\n{e.StackTrace}");

0 commit comments

Comments
 (0)