提交 969a4513 编写于 作者: J Jason Malinowski

Ensure we don't raise events for options changing to unsubscribed callers

We were grabbing the list of subscriptions before scheduling the event
back to the UI thread. This meant we might raise events on the UI thread
for somebody who has already unsubscribed on the UI thread.

Fixes #13862.
上级 38a034af
...@@ -65,17 +65,16 @@ public void OnWorkspaceDisposed(Workspace workspace) ...@@ -65,17 +65,16 @@ public void OnWorkspaceDisposed(Workspace workspace)
private void OnGlobalOptionServiceOptionChanged(object sender, OptionChangedEventArgs e) private void OnGlobalOptionServiceOptionChanged(object sender, OptionChangedEventArgs e)
{ {
var eventHandlers = GetEventHandlers(); _taskQueue?.ScheduleTask(() =>
if (eventHandlers.Length > 0)
{ {
_taskQueue?.ScheduleTask(() => // Ensure we grab the event handlers inside the scheduled task to prevent a race of people unsubscribing
// but getting the event later on the UI thread
var eventHandlers = GetEventHandlers();
foreach (var handler in eventHandlers)
{ {
foreach (var handler in eventHandlers) handler(this, e);
{ }
handler(this, e); }, "OptionsService.SetOptions");
}
}, "OptionsService.SetOptions");
}
} }
private ImmutableArray<EventHandler<OptionChangedEventArgs>> GetEventHandlers() private ImmutableArray<EventHandler<OptionChangedEventArgs>> GetEventHandlers()
...@@ -98,7 +97,7 @@ private ImmutableArray<EventHandler<OptionChangedEventArgs>> GetEventHandlers() ...@@ -98,7 +97,7 @@ private ImmutableArray<EventHandler<OptionChangedEventArgs>> GetEventHandlers()
remove remove
{ {
lock(_gate) lock (_gate)
{ {
_eventHandlers = _eventHandlers.Remove(value); _eventHandlers = _eventHandlers.Remove(value);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册