From ca23e5f4ad419eb37561836f6f84ab64bd07e854 Mon Sep 17 00:00:00 2001 From: Taiizor <41683699+Taiizor@users.noreply.github.com> Date: Mon, 18 Sep 2023 05:44:59 +0300 Subject: [PATCH] Preparing Performance Setting Page --- .../Setting/PerformanceSettingViewModel.cs | 2 +- .../Sucrose.Backgroundog/Helper/Initialize.cs | 68 ++++++++++++++----- .../Sucrose.Backgroundog/Manage/Internal.cs | 6 +- .../Sucrose.Shared.Launcher/Command/Close.cs | 5 ++ 4 files changed, 62 insertions(+), 19 deletions(-) diff --git a/src/Portal/Sucrose.Portal/ViewModels/Pages/Setting/PerformanceSettingViewModel.cs b/src/Portal/Sucrose.Portal/ViewModels/Pages/Setting/PerformanceSettingViewModel.cs index 1b06029a9..ca3f8ff23 100644 --- a/src/Portal/Sucrose.Portal/ViewModels/Pages/Setting/PerformanceSettingViewModel.cs +++ b/src/Portal/Sucrose.Portal/ViewModels/Pages/Setting/PerformanceSettingViewModel.cs @@ -50,7 +50,7 @@ private void InitializeViewModel() Counter.Title.Text = "Performans Sayaçları"; Counter.LeftIcon.Symbol = SymbolRegular.ShiftsActivity24; - Counter.Description.Text = "Tüm performans sayaçlarının çalışıp çalışmayacağı."; + Counter.Description.Text = "Tüm performans sayaçlarının arkaplanda çalışıp çalışmayacağı."; ToggleSwitch CounterState = new() { diff --git a/src/Project/Sucrose.Backgroundog/Helper/Initialize.cs b/src/Project/Sucrose.Backgroundog/Helper/Initialize.cs index 47743108d..c500df7cd 100644 --- a/src/Project/Sucrose.Backgroundog/Helper/Initialize.cs +++ b/src/Project/Sucrose.Backgroundog/Helper/Initialize.cs @@ -11,30 +11,66 @@ internal static class Initialize { public static void Start() { - SBMI.InitializeTimer.Tick += new EventHandler(InitializeTimer_Tick); - SBMI.InitializeTimer.Interval = new TimeSpan(0, 0, 1); - SBMI.InitializeTimer.Start(); + TimerCallback Callback = InitializeTimer_Callback; + SBMI.InitializeTimer = new(Callback, null, 0, 1000); } public static void Stop() { - SBMI.InitializeTimer.Stop(); + SBMI.InitializeTimer.Dispose(); } - private static void InitializeTimer_Tick(object sender, EventArgs e) + private static async void InitializeTimer_Callback(object State) { - //Libredeki cpu, ram, net bilgileri değişkene atılacak - SBHC.Start(); - - if (SSSHL.Run()) - { - //Performans şartları kontrol edilecek... - SBHP.Start(); - } - else if (SBMI.Condition) + if (SBMI.Processing) { - //Performans şartları sağlanıp live motoru kapatıldıysa veya durdurulduysa - //Live motoruna gRPC (Live.json) ile durdur mesajı gönderilir + SBMI.Processing = false; + Console.WriteLine("Callback"); + + //Libredeki cpu, ram, net bilgileri değişkene atılacak + SBHC.Start(); + + if (SSSHL.Run()) + { + Console.WriteLine("Run"); + //Performans şartları kontrol edilecek... + SBHP.Start(); + } + else if (SBMI.Condition) + { + Console.WriteLine("Condition"); + //Performans şartları sağlanıp live motoru kapatıldıysa veya durdurulduysa + //Live motoruna gRPC (Live.json) ile durdur mesajı gönderilir + } + else + { + Console.WriteLine("Deneme"); + int MaxAttempts = 5; + bool Success = false; + int IntervalInSeconds = 1; + + for (int Attempt = 0; Attempt <= MaxAttempts; Attempt++) + { + Success = SSSHL.Run(); + + if (Success) + { + Console.WriteLine("İşlem başarılı!"); + break; + } + + await Task.Delay(IntervalInSeconds * 1000); + } + + if (!Success) + { + Console.WriteLine("İşlem başarısız oldu ve 5 deneme sonunda hala true dönmedi."); + SBMI.Exit = false; + Stop(); + } + } + + SBMI.Processing = true; } } } diff --git a/src/Project/Sucrose.Backgroundog/Manage/Internal.cs b/src/Project/Sucrose.Backgroundog/Manage/Internal.cs index 268ad9353..dcf8c3654 100644 --- a/src/Project/Sucrose.Backgroundog/Manage/Internal.cs +++ b/src/Project/Sucrose.Backgroundog/Manage/Internal.cs @@ -1,4 +1,4 @@ -using System.Windows.Threading; +using Timer = System.Threading.Timer; namespace Sucrose.Backgroundog.Manage { @@ -10,6 +10,8 @@ internal static class Internal public static bool Condition = false; - public static DispatcherTimer InitializeTimer = new(); + public static bool Processing = true; + + public static Timer InitializeTimer = null; } } \ No newline at end of file diff --git a/src/Shared/Sucrose.Shared.Launcher/Command/Close.cs b/src/Shared/Sucrose.Shared.Launcher/Command/Close.cs index 566a6ae79..dbe924b1d 100644 --- a/src/Shared/Sucrose.Shared.Launcher/Command/Close.cs +++ b/src/Shared/Sucrose.Shared.Launcher/Command/Close.cs @@ -36,6 +36,11 @@ public static void Command() { SSSHP.Kill(SMR.Commandog); } + + if (SSSHP.Work(SMR.Backgroundog)) + { + SSSHP.Kill(SMR.Backgroundog); + } } WinForms.ExitThread();