commit b590340ede1594729673a50a4afa75c5371f1f0c
parent 1f6b32de7d3a89855eb761ec36a653688a243567
Author: Minerva_juppiter <ryouturn@gmail.com>
Date: Mon, 18 Mar 2024 17:35:51 +0900
通知の追加
Diffstat:
8 files changed, 65 insertions(+), 13 deletions(-)
diff --git a/App.config b/App.config
@@ -21,7 +21,7 @@
<value>50</value>
</setting>
<setting name="SliderMemory" serializeAs="String">
- <value>50</value>
+ <value>90</value>
</setting>
<setting name="SliderDisk" serializeAs="String">
<value>50</value>
diff --git a/BusynessNotification.csproj b/BusynessNotification.csproj
@@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>WinExe</OutputType>
- <TargetFramework>net8.0-windows</TargetFramework>
+ <TargetFramework>net8.0-windows10.0.17763.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
@@ -21,6 +21,7 @@
</ItemGroup>
<ItemGroup>
+ <PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.3" />
<PackageReference Include="ModernWpfUI" Version="0.9.6" />
</ItemGroup>
diff --git a/MainWindow.xaml b/MainWindow.xaml
@@ -7,7 +7,8 @@
ui:WindowHelper.UseModernWindowStyle="True"
xmlns:local="clr-namespace:BusynessNotification"
mc:Ignorable="d"
- Title="MainWindow" Height="450" Width="800">
+ Title="MainWindow" Height="450" Width="800"
+ Closing="Window_Closing">
<Grid ShowGridLines="True">
<Grid.RowDefinitions>
<RowDefinition/>
diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs
@@ -142,5 +142,10 @@ namespace BusynessNotification
return value;
}
}
+ private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
+ {
+ System.Windows.Application.Current.Shutdown();
+ System.Diagnostics.Process.Start(System.Windows.Application.ResourceAssembly.Location);
+ }
}
}
\ No newline at end of file
diff --git a/ObserveUseage.cs b/ObserveUseage.cs
@@ -1,4 +1,6 @@
-using System;
+using Microsoft.Toolkit.Uwp.Notifications;
+using Microsoft.VisualBasic.ApplicationServices;
+using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
@@ -14,13 +16,15 @@ namespace BusynessNotification
public async void Controller()
{
+ Debug.WriteLine("Controller has colled");
///設定から数値を取得
bool CheckCPU = Properties.Settings.Default.CheckCPU;
bool CheckMemory = Properties.Settings.Default.CheckMemory;
bool CheckDisk = Properties.Settings.Default.CheckDisk;
double CPUSlider = Properties.Settings.Default.SliderCPU;
- double MemorySlider = Properties.Settings.Default.SliderMemory;
+ ///double MemorySlider = Properties.Settings.Default.SliderMemory;
+ double MemorySlider = 80;
double DiskSlider = Properties.Settings.Default.SliderDisk;
int SecCPU = Properties.Settings.Default.SecCPU;
@@ -31,6 +35,9 @@ namespace BusynessNotification
int flagMemory = 0;
int flagDisk = 0;
+ Debug.WriteLine("Setting file have readed");
+ Debug.WriteLine("memorySlider " + MemorySlider);
+
///インスタンス
System.Diagnostics.PerformanceCounter cpuCounter = new System.Diagnostics.PerformanceCounter("Processor Information", "% Processor Utility", "_Total");
@@ -47,13 +54,23 @@ namespace BusynessNotification
TimerCallback timer_delegate = async state =>
{
+
+ Debug.WriteLine("timer is still waiking");
+
if (CheckCPU)
{
await Task.Run(() =>
{
- if (cpuCounter.NextValue() >= CPUSlider)
+ if (cpuCounter.NextValue() <= CPUSlider)
{
flagCPU++;
+
+ Debug.WriteLine("CPU flag" + flagCPU);
+
+ }
+ else
+ {
+ flagCPU = 0;
}
});
}
@@ -61,9 +78,19 @@ namespace BusynessNotification
{
await Task.Run(() =>
{
- if (performanceCounterRAM.NextValue() >= MemorySlider)
+
+ Debug.WriteLine(performanceCounterRAM.NextValue().ToString());
+
+ if (performanceCounterRAM.NextValue() <= MemorySlider)
{
flagMemory++;
+
+ Debug.WriteLine("RAM flag" + flagMemory);
+
+ }
+ else
+ {
+ flagMemory = 0;
}
});
}
@@ -71,17 +98,32 @@ namespace BusynessNotification
{
await Task.Run(() =>
{
- if (Disc1.NextValue() >= DiskSlider)
+ if (Disc1.NextValue() <= DiskSlider)
{
flagDisk++;
+
+ Debug.WriteLine("Disk flag" + flagDisk);
+
+ }
+ else
+ {
+ flagDisk = 0;
}
});
}
- if(flagCPU >= CPUSlider && flagMemory >= MemorySlider && flagDisk >= DiskSlider)
+ if(flagCPU >= SecCPU && flagMemory >= SecMemory && flagDisk >= SecDisk)
{
+ Debug.WriteLine("All clear");
+
timer.Dispose();
+
+ new ToastContentBuilder()
+ .AddText("Byssyness Notification")
+ .AddText("PCは使用可能な状態です。")
+ .Show();
+ Application.Exit();
}
};
timer = new System.Threading.Timer(timer_delegate,null,1000,1000);
diff --git a/Properties/Settings.Designer.cs b/Properties/Settings.Designer.cs
@@ -73,7 +73,7 @@ namespace BusynessNotification.Properties {
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("50")]
+ [global::System.Configuration.DefaultSettingValueAttribute("90")]
public double SliderMemory {
get {
return ((double)(this["SliderMemory"]));
diff --git a/Properties/Settings.settings b/Properties/Settings.settings
@@ -15,7 +15,7 @@
<Value Profile="(Default)">50</Value>
</Setting>
<Setting Name="SliderMemory" Type="System.Double" Scope="User">
- <Value Profile="(Default)">50</Value>
+ <Value Profile="(Default)">90</Value>
</Setting>
<Setting Name="SliderDisk" Type="System.Double" Scope="User">
<Value Profile="(Default)">50</Value>
diff --git a/README.md b/README.md
@@ -30,4 +30,7 @@ https://qiita.com/kyv28v/items/0a5b078d246000cb6781
http://csfun.blog49.fc2.com/blog-entry-93.html
MainWindow\͂
-https://windev.just4fun.biz/?WPF/%E8%B5%B7%E5%8B%95%E3%81%97%E3%81%A6%E3%82%82MainWindow%E3%82%92%E8%A1%A8%E7%A4%BA%E3%81%97%E3%81%9F%E3%81%8F%E3%81%AA%E3%81%84%E5%A0%B4%E5%90%88-
\ No newline at end of file
+https://windev.just4fun.biz/?WPF/%E8%B5%B7%E5%8B%95%E3%81%97%E3%81%A6%E3%82%82MainWindow%E3%82%92%E8%A1%A8%E7%A4%BA%E3%81%97%E3%81%9F%E3%81%8F%E3%81%AA%E3%81%84%E5%A0%B4%E5%90%88
+
+ʒm
+https://zenn.dev/ambleside138/articles/75e7f8fdcf4fdc+
\ No newline at end of file