Browse Source

Use the CancelSource given to TaskManager rather than make our own

tags/docs-0.9
RogueException 9 years ago
parent
commit
5b647f2251
1 changed files with 4 additions and 4 deletions
  1. +4
    -4
      src/Discord.Net/Helpers/TaskManager.cs

+ 4
- 4
src/Discord.Net/Helpers/TaskManager.cs View File

@@ -47,7 +47,7 @@ namespace Discord


lock (_lock) lock (_lock)
{ {
_cancelSource = new CancellationTokenSource();
_cancelSource = cancelSource;


if (_task != null) if (_task != null)
continue; //Another thread sneaked in and started this manager before we got a lock, loop and try again continue; //Another thread sneaked in and started this manager before we got a lock, loop and try again
@@ -66,7 +66,7 @@ namespace Discord


//Signal the rest of the tasks to stop //Signal the rest of the tasks to stop
if (firstTask.Exception != null) if (firstTask.Exception != null)
SignalError(firstTask.Exception.GetBaseException(), true);
SignalError(firstTask.Exception, true);
else else
SignalStop(); SignalStop();


@@ -113,9 +113,9 @@ namespace Discord
{ {
if (_task == null) return; //Are we running? if (_task == null) return; //Are we running?


_cancelSource.Cancel();
_stopReason = ExceptionDispatchInfo.Capture(ex); _stopReason = ExceptionDispatchInfo.Capture(ex);
_wasUnexpected = isUnexpected; _wasUnexpected = isUnexpected;
_cancelSource.Cancel();
} }
} }
public Task Error(Exception ex, bool isUnexpected = true) public Task Error(Exception ex, bool isUnexpected = true)
@@ -128,9 +128,9 @@ namespace Discord
if (task == null) return TaskHelper.CompletedTask; //Are we running? if (task == null) return TaskHelper.CompletedTask; //Are we running?
if (_cancelSource.IsCancellationRequested) return task; if (_cancelSource.IsCancellationRequested) return task;


_cancelSource.Cancel();
_stopReason = ExceptionDispatchInfo.Capture(ex); _stopReason = ExceptionDispatchInfo.Capture(ex);
_wasUnexpected = isUnexpected; _wasUnexpected = isUnexpected;
_cancelSource.Cancel();
} }
return task; return task;
} }


Loading…
Cancel
Save