Skip to content

Commit

Permalink
-added queue for background task
Browse files Browse the repository at this point in the history
  • Loading branch information
Greedeks committed Oct 14, 2024
1 parent e6dd536 commit 126ad1c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 16 deletions.
1 change: 1 addition & 0 deletions .Source/GTweak/GTweak.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
37 changes: 37 additions & 0 deletions .Source/GTweak/Utilities/Helpers/BackgroundQueue.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
32 changes: 16 additions & 16 deletions .Source/GTweak/View/ApplicationsView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public ApplicationsView()
}, 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;
Expand All @@ -48,8 +48,8 @@ private void ClickApp_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
appImage.Source = (DrawingImage)FindResource("DI_Sandtime");

BackgroundWorker backgroundWorker = new BackgroundWorker();
backgroundWorker.DoWork += delegate
BackgroundQueue backgroundQueue = new BackgroundQueue();
await backgroundQueue.QueueTask(delegate
{
if (applicationName != "YandexMusic")
{
Expand All @@ -61,35 +61,35 @@ private void ClickApp_PreviewMouseDown(object sender, MouseButtonEventArgs e)
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")
{
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();
}
}
}

Expand Down

0 comments on commit 126ad1c

Please sign in to comment.