diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Program.UnitTests/Storage/ConcurrentQueueEventHandlerTest.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Program.UnitTests/Storage/ConcurrentQueueEventHandlerTest.cs index af484b4d66..fd0e10e05f 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Program.UnitTests/Storage/ConcurrentQueueEventHandlerTest.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Program.UnitTests/Storage/ConcurrentQueueEventHandlerTest.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Collections.Concurrent; +using System.Threading.Tasks; using Microsoft.Plugin.Program.Storage; using NUnit.Framework; @@ -12,14 +13,14 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage public class ConcurrentQueueEventHandlerTest { [TestCase] - public void EventHandlerMustReturnEmptyPathForEmptyQueue() + public async Task EventHandlerMustReturnEmptyPathForEmptyQueueAsync() { // Arrange int dequeueDelay = 0; ConcurrentQueue eventHandlingQueue = new ConcurrentQueue(); // Act - string appPath = EventHandler.GetAppPathFromQueue(eventHandlingQueue, dequeueDelay); + string appPath = await EventHandler.GetAppPathFromQueueAsync(eventHandlingQueue, dequeueDelay).ConfigureAwait(false); // Assert Assert.IsEmpty(appPath); @@ -27,7 +28,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage [TestCase(1)] [TestCase(10)] - public void EventHandlerMustReturnPathForConcurrentQueueWithSameFilePaths(int itemCount) + public async Task EventHandlerMustReturnPathForConcurrentQueueWithSameFilePathsAsync(int itemCount) { // Arrange int dequeueDelay = 0; @@ -39,7 +40,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage } // Act - string pathFromQueue = EventHandler.GetAppPathFromQueue(eventHandlingQueue, dequeueDelay); + string pathFromQueue = await EventHandler.GetAppPathFromQueueAsync(eventHandlingQueue, dequeueDelay).ConfigureAwait(false); // Assert Assert.AreEqual(appPath, pathFromQueue); @@ -47,7 +48,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage } [TestCase(5)] - public void EventHandlerMustReturnPathAndRetainDifferentFilePathsInQueue(int itemCount) + public async Task EventHandlerMustReturnPathAndRetainDifferentFilePathsInQueueAsync(int itemCount) { // Arrange int dequeueDelay = 0; @@ -65,7 +66,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage } // Act - string pathFromQueue = EventHandler.GetAppPathFromQueue(eventHandlingQueue, dequeueDelay); + string pathFromQueue = await EventHandler.GetAppPathFromQueueAsync(eventHandlingQueue, dequeueDelay).ConfigureAwait(false); // Assert Assert.AreEqual(firstAppPath, pathFromQueue); @@ -73,7 +74,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage } [TestCase(5)] - public void EventHandlerMustReturnPathAndRetainAllPathsAfterEncounteringADifferentPath(int itemCount) + public async Task EventHandlerMustReturnPathAndRetainAllPathsAfterEncounteringADifferentPathAsync(int itemCount) { // Arrange int dequeueDelay = 0; @@ -96,7 +97,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage } // Act - string pathFromQueue = EventHandler.GetAppPathFromQueue(eventHandlingQueue, dequeueDelay); + string pathFromQueue = await EventHandler.GetAppPathFromQueueAsync(eventHandlingQueue, dequeueDelay).ConfigureAwait(false); // Assert Assert.AreEqual(firstAppPath, pathFromQueue); diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Storage/EventHandler.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Storage/EventHandler.cs index 689d581ad0..aee59ba3e7 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Storage/EventHandler.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Storage/EventHandler.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Concurrent; -using System.Threading; +using System.Threading.Tasks; namespace Microsoft.Plugin.Program.Storage { @@ -12,7 +12,7 @@ namespace Microsoft.Plugin.Program.Storage { // To obtain the path of the app when multiple events are added to the Concurrent queue across multiple threads. // On the first occurence of a different file path, the existing app path is to be returned without removing any more elements from the queue. - public static string GetAppPathFromQueue(ConcurrentQueue eventHandlingQueue, int dequeueDelay) + public static async Task GetAppPathFromQueueAsync(ConcurrentQueue eventHandlingQueue, int dequeueDelay) { if (eventHandlingQueue == null) { @@ -36,7 +36,7 @@ namespace Microsoft.Plugin.Program.Storage } // This delay has been added to account for the delay in events being triggered during app installation. - Thread.Sleep(dequeueDelay); + await Task.Delay(dequeueDelay).ConfigureAwait(false); } return previousAppPath; diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Storage/Win32ProgramRepository.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Storage/Win32ProgramRepository.cs index 5f1aa74f6b..3d2e7d1bf6 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Storage/Win32ProgramRepository.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Storage/Win32ProgramRepository.cs @@ -8,7 +8,6 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Globalization; using System.IO; -using System.Threading; using System.Threading.Tasks; using Wox.Infrastructure.Logger; using Wox.Infrastructure.Storage; @@ -40,15 +39,15 @@ namespace Microsoft.Plugin.Program.Storage InitializeFileSystemWatchers(); // This task would always run in the background trying to dequeue file paths from the queue at regular intervals. - Task.Run(() => + _ = Task.Run(async () => { while (true) { int dequeueDelay = 500; - string appPath = EventHandler.GetAppPathFromQueue(commonEventHandlingQueue, dequeueDelay); + string appPath = await EventHandler.GetAppPathFromQueueAsync(commonEventHandlingQueue, dequeueDelay).ConfigureAwait(false); // To allow for the installation process to finish. - Thread.Sleep(5000); + await Task.Delay(5000).ConfigureAwait(false); if (!string.IsNullOrEmpty(appPath)) {