diff --git a/Directory.Packages.props b/Directory.Packages.props index 19c6deb856d..02c9a790a75 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -63,7 +63,6 @@ - diff --git a/NuGet.config b/NuGet.config index 7a818f5f188..b5e83791aff 100644 --- a/NuGet.config +++ b/NuGet.config @@ -67,7 +67,6 @@ - diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/IRazorGeneratedDocumentExtensions.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/IRazorGeneratedDocumentExtensions.cs index 214efe87b4d..e86c686c056 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/IRazorGeneratedDocumentExtensions.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/IRazorGeneratedDocumentExtensions.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using System; using Microsoft.CodeAnalysis.Text; namespace Microsoft.AspNetCore.Razor.Language; diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Microsoft.CodeAnalysis.Razor.Workspaces.csproj b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Microsoft.CodeAnalysis.Razor.Workspaces.csproj index dd983e0656d..d74202c9306 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Microsoft.CodeAnalysis.Razor.Workspaces.csproj +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Microsoft.CodeAnalysis.Razor.Workspaces.csproj @@ -7,18 +7,12 @@ false true false - - $(NoWarn);IDE0073 - diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/NonCapturingTimer.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/NonCapturingTimer.cs new file mode 100644 index 00000000000..23bb7a90127 --- /dev/null +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/NonCapturingTimer.cs @@ -0,0 +1,44 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +// https://github.com/dotnet/runtime/blob/11c86d8acba2f248b3afb5e8594f5f41ceebf098/src/libraries/Common/src/Extensions/NonCapturingTimer/NonCapturingTimer.cs + +using System; +using System.Threading; + +namespace Microsoft.Extensions.Internal; + +// A convenience API for interacting with System.Threading.Timer in a way +// that doesn't capture the ExecutionContext. We should be using this (or equivalent) +// everywhere we use timers to avoid rooting any values stored in asynclocals. +internal static class NonCapturingTimer +{ + public static Timer Create(TimerCallback callback, object state, TimeSpan dueTime, TimeSpan period) + { + if (callback is null) + { + throw new ArgumentNullException(nameof(callback)); + } + + // Don't capture the current ExecutionContext and its AsyncLocals onto the timer + var restoreFlow = false; + try + { + if (!ExecutionContext.IsFlowSuppressed()) + { + ExecutionContext.SuppressFlow(); + restoreFlow = true; + } + + return new Timer(callback, state, dueTime, period); + } + finally + { + // Restore the current ExecutionContext + if (restoreFlow) + { + ExecutionContext.RestoreFlow(); + } + } + } +} diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Remote/RemoteAutoInsertOptions.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Remote/RemoteAutoInsertOptions.cs index 75455fd0a2c..2ef7a3224d5 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Remote/RemoteAutoInsertOptions.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Remote/RemoteAutoInsertOptions.cs @@ -1,4 +1,7 @@ -using System.Runtime.Serialization; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using System.Runtime.Serialization; using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.Settings; diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/TextDifferencing/TextDiffer.IntArray.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/TextDifferencing/TextDiffer.IntArray.cs index ba51627d53c..120685d419f 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/TextDifferencing/TextDiffer.IntArray.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/TextDifferencing/TextDiffer.IntArray.cs @@ -1,4 +1,5 @@ -// Licensed under the MIT license. See License.txt in the project root for license information. +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. using System; using System.Buffers;