提交 cdb05e13 编写于 作者: S Sam Harwell

Block the use of IForegroundNotificationService when there is no foreground thread

上级 3fd383e5
......@@ -12,6 +12,7 @@
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Roslyn.Utilities;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.Utilities;
namespace Microsoft.CodeAnalysis.Editor.Implementation.ForegroundNotification
{
......@@ -35,7 +36,11 @@ public ForegroundNotificationService()
_workQueue = new PriorityQueue();
_lastProcessedTimeInMS = Environment.TickCount;
Task.Factory.SafeStartNewFromAsync(ProcessAsync, CancellationToken.None, TaskScheduler.Default);
// Only start the background processing task if foreground work is allowed
if (ForegroundKind != ForegroundThreadDataKind.Unknown)
{
Task.Factory.SafeStartNewFromAsync(ProcessAsync, CancellationToken.None, TaskScheduler.Default);
}
}
public void RegisterNotification(Action action, IAsyncToken asyncToken, CancellationToken cancellationToken = default)
......@@ -58,6 +63,9 @@ public void RegisterNotification(Action action, int delay, IAsyncToken asyncToke
return;
}
// Assert we have some kind of foreground thread
Contract.ThrowIfTrue(CurrentForegroundThreadData.Kind == ForegroundThreadDataKind.Unknown);
var current = Environment.TickCount;
_workQueue.Enqueue(new PendingWork(current + delay, action, asyncToken, cancellationToken));
......@@ -73,6 +81,9 @@ public void RegisterNotification(Func<bool> action, int delay, IAsyncToken async
return;
}
// Assert we have some kind of foreground thread
Contract.ThrowIfTrue(CurrentForegroundThreadData.Kind == ForegroundThreadDataKind.Unknown);
var current = Environment.TickCount;
_workQueue.Enqueue(new PendingWork(current + delay, action, asyncToken, cancellationToken));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册