Skip to content

Commit

Permalink
Merge pull request #5262 from MDoerner/MakeUiDispatcherMoreDeadlockSafe
Browse files Browse the repository at this point in the history
Make the UI dispatcher more deadlock safe
  • Loading branch information
bclothier committed Nov 3, 2019
2 parents 0613e88 + 200c737 commit 6804999
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Rubberduck.Parsing/UIContext/UiDispatcher.cs
Expand Up @@ -126,6 +126,12 @@ public Task StartTask(Action action, CancellationToken token, TaskCreationOption
{
CheckInitialization();

if (_contextProvider.UiContext == SynchronizationContext.Current)
{
action.Invoke();
return Task.CompletedTask;
}

return Task.Factory.StartNew(action, token, options, _contextProvider.UiTaskScheduler);
}

Expand All @@ -141,6 +147,12 @@ public Task<T> StartTask<T>(Func<T> func, CancellationToken token, TaskCreationO
{
CheckInitialization();

if (_contextProvider.UiContext == SynchronizationContext.Current)
{
var returnValue = func();
return Task.FromResult(returnValue);
}

return Task.Factory.StartNew(func, token, options, _contextProvider.UiTaskScheduler);
}

Expand Down

0 comments on commit 6804999

Please sign in to comment.