Users Online

· Guests Online: 96

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

C# Program to Implement Sleep Method of Thread

C# Program to Implement Sleep Method of Thread

 

This is a C# Program to implement sleep method of thread.

Problem Description

This C# Program Implements Sleep method of Thread.

Problem Solution

Here Sleep pauses programs. It receives a value indicating the number of milliseconds to wait.

Program/Source Code

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();
    }
}
Program Explanation

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.

 
Runtime Test Cases
 
Elapsed Milliseconds : 498
Elapsed Ticks : 1231409
Present Date and Time : 8:36:06 PM

 

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 0.86 seconds
10,858,526 unique visits