diff --git a/src/Microsoft.AspNetCore.Mvc.Razor/Internal/RazorViewCompiler.cs b/src/Microsoft.AspNetCore.Mvc.Razor/Internal/RazorViewCompiler.cs index 9bbce19d88..0f43c19f44 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor/Internal/RazorViewCompiler.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor/Internal/RazorViewCompiler.cs @@ -181,7 +181,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal cacheEntryOptions.ExpirationTokens.Add(item.ExpirationTokens[i]); } - taskSource = new TaskCompletionSource(); + taskSource = new TaskCompletionSource(creationOptions: TaskCreationOptions.RunContinuationsAsynchronously); if (item.SupportsCompilation) { // We'll compile in just a sec, be patient. diff --git a/src/Microsoft.AspNetCore.Mvc.TagHelpers/Cache/DistributedCacheTagHelperService.cs b/src/Microsoft.AspNetCore.Mvc.TagHelpers/Cache/DistributedCacheTagHelperService.cs index 34629a2664..7db418f9b4 100644 --- a/src/Microsoft.AspNetCore.Mvc.TagHelpers/Cache/DistributedCacheTagHelperService.cs +++ b/src/Microsoft.AspNetCore.Mvc.TagHelpers/Cache/DistributedCacheTagHelperService.cs @@ -88,7 +88,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers.Cache // There is a small race condition here between TryGetValue and TryAdd that might cause the // content to be computed more than once. We don't care about this race as the probability of // happening is very small and the impact is not critical. - var tcs = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(creationOptions: TaskCreationOptions.RunContinuationsAsynchronously); _workers.TryAdd(key, tcs.Task); diff --git a/src/Microsoft.AspNetCore.Mvc.TagHelpers/CacheTagHelper.cs b/src/Microsoft.AspNetCore.Mvc.TagHelpers/CacheTagHelper.cs index 32f0824d04..de3fc45194 100644 --- a/src/Microsoft.AspNetCore.Mvc.TagHelpers/CacheTagHelper.cs +++ b/src/Microsoft.AspNetCore.Mvc.TagHelpers/CacheTagHelper.cs @@ -108,7 +108,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers var options = GetMemoryCacheEntryOptions(); options.AddExpirationToken(new CancellationChangeToken(tokenSource.Token)); options.SetSize(PlaceholderSize); - var tcs = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(creationOptions: TaskCreationOptions.RunContinuationsAsynchronously); // The returned value is ignored, we only do this so that // the compiler doesn't complain about the returned task