提交 0cf50946 编写于 作者: J Jason Malinowski

Return to capturing the foreground thread during ForegroundThreadAffinitizedObject creation

In 44142e5f I removed this code, under the belief that it wasn't
a problem. However, when WpfFact-attributed tests run, we clear the
foreground thread. Some static state (namely the
ForegroundNotificationService) is still trying to operate between test
runs, so it'd see the fallback state and then bad things would happen.
Although there's a number of terrifying things there, for now we'll
just roll it back.
上级 90673a85
......@@ -145,7 +145,7 @@ private void StartSelectedItemUpdateTask(int delay, bool updateUIWhenDone)
t => PushSelectedItemsToPresenter(t.Result),
cancellationToken,
TaskContinuationOptions.OnlyOnRanToCompletion,
ForegroundThreadAffinitizedObject.CurrentForegroundThreadData.TaskScheduler).CompletesAsyncOperation(asyncToken);
ForegroundTaskScheduler).CompletesAsyncOperation(asyncToken);
}
}
......
......@@ -50,6 +50,7 @@ internal class ForegroundThreadAffinitizedObject
{
private static readonly ForegroundThreadData s_fallbackForegroundThreadData;
private static ForegroundThreadData s_currentForegroundThreadData;
private readonly ForegroundThreadData _foregroundThreadDataWhenCreated;
internal static ForegroundThreadData CurrentForegroundThreadData
{
......@@ -65,14 +66,14 @@ internal static ForegroundThreadData CurrentForegroundThreadData
}
}
internal static Thread ForegroundThread
internal Thread ForegroundThread
{
get { return CurrentForegroundThreadData.Thread; }
get { return _foregroundThreadDataWhenCreated.Thread; }
}
internal static TaskScheduler ForegroundTaskScheduler
internal TaskScheduler ForegroundTaskScheduler
{
get { return CurrentForegroundThreadData.TaskScheduler; }
get { return _foregroundThreadDataWhenCreated.TaskScheduler; }
}
// HACK: This is a dangerous way of establishing the 'foreground' thread affinity of an
......@@ -86,6 +87,8 @@ static ForegroundThreadAffinitizedObject()
public ForegroundThreadAffinitizedObject(bool assertIsForeground = false)
{
_foregroundThreadDataWhenCreated = CurrentForegroundThreadData;
// For sanity's sake, ensure that our idea of "foreground" is the same as WPF's. But we won't assert
// anything if we haven't figured it out yet.
Contract.ThrowIfFalse(
......
......@@ -49,7 +49,7 @@ private WorkspaceTaskQueue CreateQueue()
{
// At this point, we have to know what the UI thread is.
Contract.ThrowIfTrue(ForegroundThreadAffinitizedObject.CurrentForegroundThreadData.Kind == ForegroundThreadDataKind.Unknown);
return new WorkspaceTaskQueue(_factory, ForegroundThreadAffinitizedObject.ForegroundTaskScheduler);
return new WorkspaceTaskQueue(_factory, ForegroundThreadAffinitizedObject.CurrentForegroundThreadData.TaskScheduler);
}
public Task ScheduleTask(Action taskAction, string taskName, CancellationToken cancellationToken = default(CancellationToken))
......
......@@ -71,7 +71,7 @@ private static async Task RegisterWorkspaceHostAsync(Workspace workspace, Remote
await Task.Factory.SafeStartNew(() =>
{
vsWorkspace.DeferredState.ProjectTracker.RegisterWorkspaceHost(host);
}, CancellationToken.None, ForegroundThreadAffinitizedObject.ForegroundTaskScheduler).ConfigureAwait(false);
}, CancellationToken.None, ForegroundThreadAffinitizedObject.CurrentForegroundThreadData.TaskScheduler).ConfigureAwait(false);
}
private ServiceHubRemoteHostClient(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册