Elapsed Milliseconds : 498 Elapsed Ticks : 1231409 Present Date and Time : 8:36:06 PM
This is a C# Program to implement sleep method of thread.
This C# Program Implements Sleep method of Thread.
Here Sleep pauses programs. It receives a value indicating the number of milliseconds to wait.
Here is source code of the C# Program to Implement Sleep method of Thread. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.
/* * C# Program to Implement Sleep method of Thread */ using System; using System.Diagnostics; using System.Threading; class Program { static void Main() { var stopwatch = Stopwatch.StartNew(); Thread.Sleep(500); stopwatch.Stop(); Console.WriteLine("Elapsed Milliseconds : {0}", stopwatch.ElapsedMilliseconds); Console.WriteLine("Elapsed Ticks : {0}", stopwatch.ElapsedTicks); Console.WriteLine("Present Date and Time : {0}", DateTime.Now.ToLongTimeString()); Console.ReadLine(); } }
In this C# Program, the Sleep() function is used to pauses program. It receives a value indicating the number of milliseconds to wait. Then ElapsedMilliseconds() function is used to print the Elapsed Milliseconds. The ElapsedTicks() function is used to print the Elapsed Ticks. The ToLongTimeString() function is used to print the Present Date and Time.
Elapsed Milliseconds : 498 Elapsed Ticks : 1231409 Present Date and Time : 8:36:06 PM