From e21dc21b403fdc7d4d8b5ba96cbe3fa41b9548db Mon Sep 17 00:00:00 2001 From: Andrew Lock Date: Wed, 2 Jan 2019 17:12:26 +0000 Subject: [PATCH] Use Task.Run instead of Task.Factory.StartNew (#611) Addresses #571 Using `TaskCreationOptions.LongRunning` creates a dedicated thread, but it's released on the first await. Using Task.Run uses the thread pool instead --- .../Logging.AzureAppServices/src/BatchingLoggerProvider.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Logging/Logging.AzureAppServices/src/BatchingLoggerProvider.cs b/src/Logging/Logging.AzureAppServices/src/BatchingLoggerProvider.cs index 5b375a2b5a..7d0bd3ae40 100644 --- a/src/Logging/Logging.AzureAppServices/src/BatchingLoggerProvider.cs +++ b/src/Logging/Logging.AzureAppServices/src/BatchingLoggerProvider.cs @@ -75,7 +75,7 @@ namespace Microsoft.Extensions.Logging.AzureAppServices internal abstract Task WriteMessagesAsync(IEnumerable messages, CancellationToken token); - private async Task ProcessLogQueue(object state) + private async Task ProcessLogQueue() { while (!_cancellationTokenSource.IsCancellationRequested) { @@ -143,10 +143,7 @@ namespace Microsoft.Extensions.Logging.AzureAppServices new BlockingCollection(new ConcurrentQueue(), _queueSize.Value); _cancellationTokenSource = new CancellationTokenSource(); - _outputTask = Task.Factory.StartNew( - ProcessLogQueue, - null, - TaskCreationOptions.LongRunning); + _outputTask = Task.Run(ProcessLogQueue); } private void Stop()