Kitnkiller schreef:...Eerdere citaten tonen
Bugged schreef:De stresstest starten?Eerdere citaten tonen
Kitnkiller schreef:AfbeeldingEerdere citaten tonen
Dylan schreef:Mijn eerste programma met C# (CPU Stress test)
Wat doet launchStress()?
Ja, maar op welke manier?private void launchStress() { while(true) { launchStress(); } }
Spoiler tonen
Codeblok (voorbeeld.php):
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Diagnostics;
namespace CPUStressTest
{
class Program
{
static void Main(string[] args)
{
AppDomain.CurrentDomain.ProcessExit += new EventHandler(OnProcessExit);
Console.Title = "CPU Stress Test by DazDylz";
Console.BackgroundColor = ConsoleColor.DarkRed;
Console.ForegroundColor = ConsoleColor.Yellow;
string[] texts = new string[6] {
"Welcome to my CPU Stress Tester!",
"This is the first time I made a program in C#",
"so dont expect something good
","nr",
"Press enter to quit the program (may take a second)",
"nrnr"
};
initTest(texts);
Console.BackgroundColor = ConsoleColor.Green;
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("Press any key to start the test");
Thread TitleBar = new Thread(new ThreadStart(titleBar));
Console.Read();
Console.ResetColor();
Console.Clear();
TitleBar.Start();
launchStress();
while (true)
{
if (Console.ReadKey().Key.ToString().ToUpper() == "ENTER")
{
OnProcessExit(); // OVERLOAD!!!
}
}
}
static void OnProcessExit(object sender, EventArgs e)
{
Console.WriteLine("Bye!");
Environment.Exit(0);
}
static void OnProcessExit()
{
Console.WriteLine("Bye!");
Environment.Exit(0);
}
static void initTest(string[] texts)
{
foreach(string text in texts) {
Console.WriteLine("{0}", text.ToString());
}
}
static void titleBar()
{
PerformanceCounter cpuUsage;
cpuUsage = new PerformanceCounter();
cpuUsage.CategoryName = "Processor";
cpuUsage.CounterName = "% Processor Time";
cpuUsage.InstanceName = "_Total";
while (true)
{
Console.Title = "CPU Usage: " + Math.Round(cpuUsage.NextValue(), 1) + "%";
Thread.Sleep(500);
}
}
static int getRandomInt()
{
return new Random().Next(1, 51023);
}
static void stress()
{
while (true)
{
Console.Write(getRandomInt() * getRandomInt());
}
}
static void launchStress()
{
for (int core = 0; core < Environment.ProcessorCount; core++)
{
Thread threadStress = new Thread(new ThreadStart(stress));
threadStress.Start();
}
}
}
}
toevoeging op 27 mei 2015, 13:05:43:
Afbeelding niet beschikbaarDe bron kon niet worden geladen (i.imgur.com).Bron openen ↗toevoeging op 27 mei 2015, 13:07:13:
Afbeelding niet beschikbaarDe bron kon niet worden geladen (i.imgur.com).Bron openen ↗
