Skip to content

Commit 6804999

Browse files
authored
Merge pull request #5262 from MDoerner/MakeUiDispatcherMoreDeadlockSafe
Make the UI dispatcher more deadlock safe
2 parents 0613e88 + 200c737 commit 6804999

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Rubberduck.Parsing/UIContext/UiDispatcher.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ public Task StartTask(Action action, CancellationToken token, TaskCreationOption
126126
{
127127
CheckInitialization();
128128

129+
if (_contextProvider.UiContext == SynchronizationContext.Current)
130+
{
131+
action.Invoke();
132+
return Task.CompletedTask;
133+
}
134+
129135
return Task.Factory.StartNew(action, token, options, _contextProvider.UiTaskScheduler);
130136
}
131137

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

150+
if (_contextProvider.UiContext == SynchronizationContext.Current)
151+
{
152+
var returnValue = func();
153+
return Task.FromResult(returnValue);
154+
}
155+
144156
return Task.Factory.StartNew(func, token, options, _contextProvider.UiTaskScheduler);
145157
}
146158

0 commit comments

Comments
 (0)