-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchanges.patch
More file actions
108 lines (102 loc) · 4.23 KB
/
changes.patch
File metadata and controls
108 lines (102 loc) · 4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
diff --git a/InfoAboutPC/Form1.Designer.cs b/InfoAboutPC/Form1.Designer.cs
index 75088c0..e5a12ab 100644
--- a/InfoAboutPC/Form1.Designer.cs
+++ b/InfoAboutPC/Form1.Designer.cs
@@ -95,8 +95,8 @@
#endregion
private System.Windows.Forms.Button btnGetInfo;
- private System.Windows.Forms.TreeView treeViewInfo; // Объявляем TreeView
- private System.Windows.Forms.DataVisualization.Charting.Chart chartCPU; // Объявляем график CPU
- private System.Windows.Forms.DataVisualization.Charting.Chart chartRAM; // Объявляем график RAM
+ private System.Windows.Forms.TreeView treeViewInfo;
+ private System.Windows.Forms.DataVisualization.Charting.Chart chartCPU;
+ private System.Windows.Forms.DataVisualization.Charting.Chart chartRAM;
}
}
\ No newline at end of file
diff --git a/InfoAboutPC/Form1.cs b/InfoAboutPC/Form1.cs
index e08c8ec..7c8d00f 100644
--- a/InfoAboutPC/Form1.cs
+++ b/InfoAboutPC/Form1.cs
@@ -1,5 +1,4 @@
-
-using System.Diagnostics;
+using System.Diagnostics;
using System.Management;
using System.Net;
using System.Windows.Forms.DataVisualization.Charting;
@@ -8,6 +7,7 @@ namespace InfoAboutPC
{
public partial class Form1 : Form
{
+ private System.Windows.Forms.Timer timer;
private PerformanceCounter cpuCounter;
private PerformanceCounter ramCounter;
@@ -21,12 +21,29 @@ namespace InfoAboutPC
private void InitializePerformanceCounters()
{
cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
- ramCounter = new PerformanceCounter("Memory", "Available MBytes");
+ ramCounter = new PerformanceCounter("Memory", "%Commited Bytes In Use");
+ timer = new System.Windows.Forms.Timer();
+ timer.Interval = 1000;
+ timer.Tick += Timer_Tick;
+ timer.Start();
+ }
+
+ private void Timer_Tick(object sender, EventArgs e)
+ {
+ float currentCpuUsage = cpuCounter.NextValue();
+ float currentRamUsage = ramCounter.NextValue();
+ chartCPU.Series["CPU Usage"].Points.AddY(currentCpuUsage);
+ chartRAM.Series["RAM Usage"].Points.AddY(currentRamUsage);
+ if (chartCPU.Series["CPU Usage"].Points.Count > 60)
+ chartCPU.Series["CPU Usage"].Points.RemoveAt(0);
+ if (chartRAM.Series["RAM Usage"].Points.Count > 60)
+ chartRAM.Series["RAM Usage"].Points.RemoveAt(0);
}
private void SetupCharts()
{
- chartCPU.Series.Clear();
+ ChartArea chartAreaCPU = new ChartArea("CPUUsageArea");
+ chartCPU.ChartAreas.Add(chartAreaCPU);
var seriesCPU = new Series("CPU Usage")
{
ChartType = SeriesChartType.Line,
@@ -36,8 +53,9 @@ namespace InfoAboutPC
};
chartCPU.Series.Add(seriesCPU);
- chartRAM.Series.Clear();
- var seriesRAM = new Series("Available RAM")
+ ChartArea chartAreaRAM = new ChartArea("RAMUsageArea");
+ chartRAM.ChartAreas.Add(chartAreaRAM);
+ var seriesRAM = new Series("RAM Usage")
{
ChartType = SeriesChartType.Line,
Color = Color.Blue,
@@ -51,7 +69,6 @@ namespace InfoAboutPC
{
treeViewInfo.Nodes.Clear();
GetSystemInfo();
- UpdateCharts();
}
private void GetSystemInfo()
@@ -114,19 +131,6 @@ namespace InfoAboutPC
treeViewInfo.Nodes.Add(systemInfoNode);
}
- private void UpdateCharts()
- {
- float cpuUsage = cpuCounter.NextValue();
- float availableRam = ramCounter.NextValue();
-
- chartCPU.Series["CPU Usage"].Points.AddY(cpuUsage);
-
- chartRAM.Series["Available RAM"].Points.AddY(availableRam);
-
- treeViewInfo.Nodes[0].Nodes.Add($"Текущая загрузка CPU: {cpuUsage}%");
- treeViewInfo.Nodes[0].Nodes.Add($"Доступная RAM: {availableRam} MB");
- }
-
private string GetLocalIPAddress()
{
string localIP = "Не удалось получить IP-адрес";