Skip to content

Instantly share code, notes, and snippets.

@TiagoSoczek
Created December 6, 2017 18:04
Show Gist options
  • Select an option

  • Save TiagoSoczek/69898cf3a4902aaddb0e4f9e3b5fdace to your computer and use it in GitHub Desktop.

Select an option

Save TiagoSoczek/69898cf3a4902aaddb0e4f9e3b5fdace to your computer and use it in GitHub Desktop.
private void HighCpu()
{
int percentage = 80;
int duration = 15;
var resetEvent = new ManualResetEventSlim();
for (int i = 0; i < Environment.ProcessorCount; i++)
{
var th = new Thread(() =>
{
Stopwatch watch = new Stopwatch();
watch.Start();
while (!resetEvent.IsSet)
{
if (watch.ElapsedMilliseconds > percentage)
{
Thread.Sleep(100 - percentage);
watch.Reset();
watch.Start();
}
}
});
th.Start();
}
Thread.Sleep(duration * 1000);
resetEvent.Set();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment