Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- namespace TimePeriod
- {
- class Program
- {
- [DllImport("winmm.dll")]
- internal static extern uint timeBeginPeriod(uint period);
- [DllImport("winmm.dll")]
- internal static extern uint timeEndPeriod(uint period);
- const int sleeptime = 5;
- static void Main(string[] args)
- {
- Stopwatch stopwatch = new Stopwatch();
- stopwatch.Restart();
- Thread.Sleep(sleeptime);
- stopwatch.Stop();
- Console.WriteLine($"Thread.Sleep({sleeptime}) Normal--{stopwatch.ElapsedMilliseconds}ms--{stopwatch.ElapsedTicks}Ticks");
- timeBeginPeriod(1);
- stopwatch.Restart();
- Thread.Sleep(sleeptime);
- stopwatch.Stop();
- Console.WriteLine($"Thread.Sleep({sleeptime}) timeBeginPeriod(1)--{stopwatch.ElapsedMilliseconds}ms--{stopwatch.ElapsedTicks}Ticks");
- timeEndPeriod(1);
- Task.Run(() =>
- {
- int count = 50;
- while (count > 0)
- {
- count--;
- stopwatch.Restart();
- Thread.Sleep(sleeptime);
- Console.WriteLine($"Thread.Sleep({sleeptime}) Normal--{stopwatch.ElapsedMilliseconds}ms--{stopwatch.ElapsedTicks}Ticks");
- stopwatch.Stop();
- }
- });
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement