Computer Science, asked by psebmkjindal8687, 11 months ago

How to make a C# program sleep for x milliseconds?

Answers

Answered by omegads04
0

using System;

using System.Diagnostics;

using System.Threading;

class Program

{

   static void Main()

   {

       Demonstrates 3 different ways of calling Sleep.

       var stopwatch = Stopwatch . Start New();

       Thread.Sleep(0);

       stopwatch.Stop();

       Console.Write Line (stopwatch .Elapsed Milliseconds);

       Console.Write Line (Date Time .Now. To Long Time String());

       stopwatch = Stopwatch. Start New();

       Thread.Sleep(5000);

       stopwatch.Stop();

       Console.Write Line (stop watch. Elapsed Milli seconds);

       Console. Write Line (Date Time . Now. To Long Time String());

       stopwatch = Stopwatch. Start New();

       System.Threading.Thread.Sleep(1000);

       stopwatch.Stop();

       Console. Write Line(stopwatch . Elapsed Milli seconds);

       Bonus: shows Spin Wait method.

     stopwatch = Stopwatch .Start New();

       Thread.Spin Wait(100000 * 10000);

       stopwatch . Stop();

       Console. Write Line (stopwatch. Elapsed Milli seconds);

   }

}

Similar questions