Don't capture asynclocals onto Timer
This commit is contained in:
parent
1e8e541f65
commit
5e083c371b
|
|
@ -149,12 +149,35 @@ namespace Microsoft.CodeAnalysis.Razor
|
||||||
// Access to the timer is protected by the lock in Enqueue and in Timer_Tick
|
// Access to the timer is protected by the lock in Enqueue and in Timer_Tick
|
||||||
if (_timer == null)
|
if (_timer == null)
|
||||||
{
|
{
|
||||||
// Timer will fire after a fixed delay, but only once.
|
// Don't capture asynclocals onto Timer
|
||||||
_timer = new Timer(Timer_Tick, null, Delay, Timeout.InfiniteTimeSpan);
|
bool restoreFlow = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!ExecutionContext.IsFlowSuppressed())
|
||||||
|
{
|
||||||
|
ExecutionContext.SuppressFlow();
|
||||||
|
restoreFlow = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Timer will fire after a fixed delay, but only once.
|
||||||
|
_timer = new Timer(state => ((BackgroundDocumentGenerator)state).Timer_Tick(), this, Delay, Timeout.InfiniteTimeSpan);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (restoreFlow)
|
||||||
|
{
|
||||||
|
ExecutionContext.RestoreFlow();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void Timer_Tick(object state) // Yeah I know.
|
private void Timer_Tick()
|
||||||
|
{
|
||||||
|
_ = TimerTick();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task TimerTick()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -208,7 +231,8 @@ namespace Microsoft.CodeAnalysis.Razor
|
||||||
{
|
{
|
||||||
// This is something totally unexpected, let's just send it over to the workspace.
|
// This is something totally unexpected, let's just send it over to the workspace.
|
||||||
await Task.Factory.StartNew(
|
await Task.Factory.StartNew(
|
||||||
() => _projectManager.ReportError(ex),
|
(p) => ((ProjectSnapshotManagerBase)p).ReportError(ex),
|
||||||
|
_projectManager,
|
||||||
CancellationToken.None,
|
CancellationToken.None,
|
||||||
TaskCreationOptions.None,
|
TaskCreationOptions.None,
|
||||||
_foregroundDispatcher.ForegroundScheduler);
|
_foregroundDispatcher.ForegroundScheduler);
|
||||||
|
|
@ -218,7 +242,8 @@ namespace Microsoft.CodeAnalysis.Razor
|
||||||
private void ReportError(DocumentSnapshot document, Exception ex)
|
private void ReportError(DocumentSnapshot document, Exception ex)
|
||||||
{
|
{
|
||||||
GC.KeepAlive(Task.Factory.StartNew(
|
GC.KeepAlive(Task.Factory.StartNew(
|
||||||
() => _projectManager.ReportError(ex),
|
(p) => ((ProjectSnapshotManagerBase)p).ReportError(ex),
|
||||||
|
_projectManager,
|
||||||
CancellationToken.None,
|
CancellationToken.None,
|
||||||
TaskCreationOptions.None,
|
TaskCreationOptions.None,
|
||||||
_foregroundDispatcher.ForegroundScheduler));
|
_foregroundDispatcher.ForegroundScheduler));
|
||||||
|
|
|
||||||
|
|
@ -213,8 +213,26 @@ namespace Microsoft.VisualStudio.Editor.Razor
|
||||||
{
|
{
|
||||||
if (_idleTimer == null)
|
if (_idleTimer == null)
|
||||||
{
|
{
|
||||||
// Timer will fire after a fixed delay, but only once.
|
// Don't capture asynclocals onto Timer
|
||||||
_idleTimer = new Timer(Timer_Tick, null, IdleDelay, Timeout.InfiniteTimeSpan);
|
bool restoreFlow = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!ExecutionContext.IsFlowSuppressed())
|
||||||
|
{
|
||||||
|
ExecutionContext.SuppressFlow();
|
||||||
|
restoreFlow = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Timer will fire after a fixed delay, but only once.
|
||||||
|
_idleTimer = new Timer(state => ((DefaultVisualStudioRazorParser)state).Timer_Tick(), this, IdleDelay, Timeout.InfiniteTimeSpan);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (restoreFlow)
|
||||||
|
{
|
||||||
|
ExecutionContext.RestoreFlow();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -337,7 +355,7 @@ namespace Microsoft.VisualStudio.Editor.Razor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Timer_Tick(object state)
|
private void Timer_Tick()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue