-
Notifications
You must be signed in to change notification settings - Fork 0
/
Performance.cs
104 lines (97 loc) · 3.58 KB
/
Performance.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.IO;
using HtmlAgilityPack;
using System.Threading;
using System.Diagnostics;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
namespace mission_impossible_code_assassin
{
class Performance
{
public static void check_state()
{
while (true)
{
if (Data.Download_Thread != null) // Check If The Download Thread is Null Or Not
{
if (Data.Download_Thread.ThreadState != System.Threading.ThreadState.Running)
{
Data.Download_Thread.Abort();
Data.downloading = false;
}
}
for (int i = 0; i < Data.nThreads; i++)
{
if (Data.threads_parse[i] != null)
{
if (Data.threads_parse[i].ThreadState == System.Threading.ThreadState.Stopped)
{
Data.threads_parse[i].Abort();
if (Data.threads_parse[i] != null)
if (Data.threads_parse[i].ThreadState == System.Threading.ThreadState.Running || Data.threads_parse[i].ThreadState == System.Threading.ThreadState.Suspended)
Data.threads_parse[i].Abort();
Data.threads_parse[i] = null;
Data.nThreads--;
}
}
}
Data._AREvt.WaitOne(10, true);
}
}
public static void check_internet()
{
Monitor.Enter(Data.is_there_internet);
while (true)
{
try
{
IPHostEntry i = Dns.GetHostEntry("www.google.com"); // Send Request To Google
Data.is_there_internet = true;
}
catch
{
Data.is_there_internet = false;
}
}
Monitor.Exit(Data.is_there_internet);
}
public static void getramusage()
{
PerformanceCounter ram;
ram = new PerformanceCounter("Memory", "Available MBytes", true);
Data.available_ram = ram.NextValue().ToString();
}
public static void getCPUCOunter()
{
PerformanceCounter cpuCounter = new PerformanceCounter();
cpuCounter.CategoryName = "Processor";
cpuCounter.CounterName = "% Processor Time";
cpuCounter.InstanceName = "_Total";
// will always start at 0
dynamic firstValue = cpuCounter.NextValue();
System.Threading.Thread.Sleep(1000);
// now matches task manager reading
string secondValue = cpuCounter.NextValue().ToString();
Data.cpuUsage = secondValue;
}
public static void update_Usage()
{
Data.CpuRamStatus = new Thread(() => getCPUCOunter());
Data.CpuRamStatus.Priority = ThreadPriority.Lowest;
Data.CpuRamStatus.IsBackground = true;
Data.CpuRamStatus.Start();
Data.CpuRamStatus = new Thread(() => getramusage());
Data.CpuRamStatus.Priority = ThreadPriority.Lowest;
Data.CpuRamStatus.IsBackground = true;
Data.CpuRamStatus.Start();
}
}
}