Created
December 6, 2017 18:04
-
-
Save TiagoSoczek/69898cf3a4902aaddb0e4f9e3b5fdace to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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