From 060698a52f3e0847861b1516612c6058a436bef5 Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Thu, 13 Sep 2018 18:30:37 -0700 Subject: [PATCH] Update to use non-capturing timer --- build/dependencies.props | 1 + .../BackgroundDocumentGenerator.cs | 22 +++--------------- ...osoft.CodeAnalysis.Razor.Workspaces.csproj | 1 + .../DefaultVisualStudioRazorParser.cs | 23 +++---------------- 4 files changed, 8 insertions(+), 39 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 3d59a7a667..1bc3096ec5 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -17,6 +17,7 @@ 2.2.0-preview3-35252 2.1.0 2.2.0-preview3-35252 + 2.2.0-preview3-35252 2.2.0-preview3-35252 2.0.9 2.1.3 diff --git a/src/Microsoft.CodeAnalysis.Razor.Workspaces/DocumentGenerator/BackgroundDocumentGenerator.cs b/src/Microsoft.CodeAnalysis.Razor.Workspaces/DocumentGenerator/BackgroundDocumentGenerator.cs index 2ddde78e98..eba3c12e25 100644 --- a/src/Microsoft.CodeAnalysis.Razor.Workspaces/DocumentGenerator/BackgroundDocumentGenerator.cs +++ b/src/Microsoft.CodeAnalysis.Razor.Workspaces/DocumentGenerator/BackgroundDocumentGenerator.cs @@ -8,6 +8,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Razor.ProjectSystem; +using Microsoft.Extensions.Internal; namespace Microsoft.CodeAnalysis.Razor { @@ -149,26 +150,9 @@ namespace Microsoft.CodeAnalysis.Razor // Access to the timer is protected by the lock in Enqueue and in Timer_Tick if (_timer == null) { - // Don't capture asynclocals onto Timer - 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(); - } - } + // Timer will fire after a fixed delay, but only once. + _timer = NonCapturingTimer.Create(state => ((BackgroundDocumentGenerator)state).Timer_Tick(), this, Delay, Timeout.InfiniteTimeSpan); } } diff --git a/src/Microsoft.CodeAnalysis.Razor.Workspaces/Microsoft.CodeAnalysis.Razor.Workspaces.csproj b/src/Microsoft.CodeAnalysis.Razor.Workspaces/Microsoft.CodeAnalysis.Razor.Workspaces.csproj index e7f29a2fb0..ca09c13e78 100644 --- a/src/Microsoft.CodeAnalysis.Razor.Workspaces/Microsoft.CodeAnalysis.Razor.Workspaces.csproj +++ b/src/Microsoft.CodeAnalysis.Razor.Workspaces/Microsoft.CodeAnalysis.Razor.Workspaces.csproj @@ -13,6 +13,7 @@ + diff --git a/src/Microsoft.VisualStudio.Editor.Razor/DefaultVisualStudioRazorParser.cs b/src/Microsoft.VisualStudio.Editor.Razor/DefaultVisualStudioRazorParser.cs index 601dba2fc2..25d446febf 100644 --- a/src/Microsoft.VisualStudio.Editor.Razor/DefaultVisualStudioRazorParser.cs +++ b/src/Microsoft.VisualStudio.Editor.Razor/DefaultVisualStudioRazorParser.cs @@ -11,6 +11,7 @@ using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.Legacy; using Microsoft.CodeAnalysis.Razor; using Microsoft.CodeAnalysis.Razor.Editor; +using Microsoft.Extensions.Internal; using Microsoft.VisualStudio.Text; using static Microsoft.VisualStudio.Editor.Razor.BackgroundParser; using ITextBuffer = Microsoft.VisualStudio.Text.ITextBuffer; @@ -213,26 +214,8 @@ namespace Microsoft.VisualStudio.Editor.Razor { if (_idleTimer == null) { - // Don't capture asynclocals onto Timer - 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(); - } - } + // Timer will fire after a fixed delay, but only once. + _idleTimer = NonCapturingTimer.Create(state => ((DefaultVisualStudioRazorParser)state).Timer_Tick(), this, IdleDelay, Timeout.InfiniteTimeSpan); } } }