提交 1b544075 编写于 作者: J Jason Malinowski 提交者: GitHub

Merge pull request #13934 from jasonmalinowski/fix-option-race

Fix option race causing crashes
......@@ -143,6 +143,17 @@ public void RefreshOption(OptionKey optionKey, object newValue)
{
lock (_gate)
{
object oldValue;
if (_currentValues.TryGetValue(optionKey, out oldValue))
{
if (object.Equals(oldValue, newValue))
{
// Value is still the same, no reason to raise events
return;
}
}
_currentValues = _currentValues.SetItem(optionKey, newValue);
}
......
......@@ -65,17 +65,16 @@ public void OnWorkspaceDisposed(Workspace workspace)
private void OnGlobalOptionServiceOptionChanged(object sender, OptionChangedEventArgs e)
{
var eventHandlers = GetEventHandlers();
if (eventHandlers.Length > 0)
_taskQueue?.ScheduleTask(() =>
{
_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);
}
}, "OptionsService.SetOptions");
}
handler(this, e);
}
}, "OptionsService.SetOptions");
}
private ImmutableArray<EventHandler<OptionChangedEventArgs>> GetEventHandlers()
......@@ -98,7 +97,7 @@ private ImmutableArray<EventHandler<OptionChangedEventArgs>> GetEventHandlers()
remove
{
lock(_gate)
lock (_gate)
{
_eventHandlers = _eventHandlers.Remove(value);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册