Skip to content

Portable Tool for an Ideal Windows Setup

-added queue for background task

Greedeks126ad1cc1613
diff --git a/.Source/GTweak/GTweak.csproj b/.Source/GTweak/GTweak.csproj
index 00bf33ab..098d101f 100644
--- a/.Source/GTweak/GTweak.csproj
+++ b/.Source/GTweak/GTweak.csproj
@@ -248,6 +248,7 @@
<Compile Include="Core\Model\MainModel.cs" />
<Compile Include="Utilities\BlockRunTweaker.cs" />
<Compile Include="Utilities\DisablingWinKeys.cs" />
+ <Compile Include="Utilities\Helpers\BackgroundQueue.cs" />
<Compile Include="Utilities\Helpers\RegistryHelp.cs" />
<Compile Include="Utilities\Settings.cs" />
<Compile Include="Utilities\Helpers\TakingOwnership.cs" />
diff --git a/.Source/GTweak/Utilities/Helpers/BackgroundQueue.cs b/.Source/GTweak/Utilities/Helpers/BackgroundQueue.cs
new file mode 100644
index 00000000..0f15566a
--- /dev/null
+++ b/.Source/GTweak/Utilities/Helpers/BackgroundQueue.cs
@@ -0,0 +1,37 @@
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace GTweak.Utilities.Helpers
+{
+ internal class BackgroundQueue
+ {
+ private Task previousTask = Task.FromResult(true);
+ private readonly object key = new object();
+ public Task QueueTask(Action action)
+ {
+ lock (key)
+ {
+ previousTask = previousTask.ContinueWith(t => action()
+ , CancellationToken.None
+ , TaskContinuationOptions.None
+ , TaskScheduler.Default);
+ return previousTask;
+ }
+ }
+
+ public Task<T> QueueTask<T>(Func<T> work)
+ {
+ lock (key)
+ {
+ var task = previousTask.ContinueWith(t => work()
+ , CancellationToken.None
+ , TaskContinuationOptions.None
+ , TaskScheduler.Default);
+ previousTask = task;
+ return task;
+ }
+ }
+ public bool IsQueueCompleted() => previousTask.IsCompleted;
+ }
+}
diff --git a/.Source/GTweak/View/ApplicationsView.xaml.cs b/.Source/GTweak/View/ApplicationsView.xaml.cs
index 63954e58..51568ecb 100644
--- a/.Source/GTweak/View/ApplicationsView.xaml.cs
+++ b/.Source/GTweak/View/ApplicationsView.xaml.cs
@@ -39,7 +39,7 @@ namespace GTweak.View
}, Application.Current.Dispatcher);
}
- private void ClickApp_PreviewMouseDown(object sender, MouseButtonEventArgs e)
+ private async void ClickApp_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
Image appImage = (Image)sender;
applicationName = appImage.Name;
@@ -48,8 +48,8 @@ namespace GTweak.View
{
appImage.Source = (DrawingImage)FindResource("DI_Sandtime");
- BackgroundWorker backgroundWorker = new BackgroundWorker();
- backgroundWorker.DoWork += delegate
+ BackgroundQueue backgroundQueue = new BackgroundQueue();
+ await backgroundQueue.QueueTask(delegate
{
if (applicationName != "YandexMusic")
{
@@ -61,18 +61,16 @@ namespace GTweak.View
UninstallingApps.IsAppDeletedList["Yandex.Music"] = true;
UninstallingApps.DeletedApp("Yandex.Music");
}
- };
- backgroundWorker.RunWorkerCompleted += async delegate
+ });
+ if (backgroundQueue.IsQueueCompleted())
{
- await Task.Delay(25000);
+ await Task.Delay(15000);
if (applicationName != "YandexMusic")
UninstallingApps.IsAppDeletedList[appImage.Name] = false;
else
UninstallingApps.IsAppDeletedList["Yandex.Music"] = false;
UpdateViewStateApps();
- backgroundWorker.Dispose();
- };
- backgroundWorker.RunWorkerAsync();
+ }
}
if (e.LeftButton == MouseButtonState.Pressed && appImage.Source == (DrawingImage)FindResource("DA_DI_" + appImage.Name) && applicationName == "OneDrive")
@@ -80,16 +78,18 @@ namespace GTweak.View
appImage.Source = (DrawingImage)FindResource("DI_Sandtime");
new ViewNotification().Show("", (string)FindResource("title1_notification"), (string)FindResource("onedrive_notification"));
- BackgroundWorker backgroundWorker = new BackgroundWorker();
- backgroundWorker.DoWork += delegate { UninstallingApps.ResetOneDrive(); };
- backgroundWorker.RunWorkerCompleted += async delegate
+ BackgroundQueue backgroundQueue = new BackgroundQueue();
+ await backgroundQueue.QueueTask(delegate
+ {
+ UninstallingApps.ResetOneDrive();
+ });
+ if (backgroundQueue.IsQueueCompleted())
{
- await Task.Delay(15000);
+ await Task.Delay(6000);
UninstallingApps.IsAppDeletedList[appImage.Name] = false;
UpdateViewStateApps();
- backgroundWorker.Dispose();
- };
- backgroundWorker.RunWorkerAsync();
+ UpdateViewStateApps();
+ }
}
}