Home c# Pause in C #

Pause in C #

Author

Date

Category

Tell me how you can pause the program for a while?

System.Threading.Thread.Sleep (500);

Answer 1, authority 100%

Sample Approach:

  1. start a new thread,
  2. enter a loop in the stream,
  3. in a loop to do work and fall asleep for a while.

Code example:

using System;
using System.Threading;
public class ThreadExample {
  public static void ThreadProc () {
    while (true) {
      // TODO: This does what needs to be done
      Thread.Sleep (1000);
    }
  }
  public static void Main () {
    Thread t = new Thread (new ThreadStart (ThreadProc));
    t.Start ();
    Thread.Sleep (1000);
    t.Join ();
  }
}

Answer 2, authority 50%

System.Windows.Threading.DispatcherTimer // for WPF interface
System.Timers.Timer
System.Web.UI.Timer
System.Threading.Timer
Microsoft.Win32.SystemEvents.CreateTimer (int) + (Microsoft.Win32.SystemEvents.TimerElapsed)
  1. create timer
  2. Set spacing
  3. Subscribe to Tick, Elapsed, etc
  4. Start ()

There is also an interesting class. It is called Stopwatch . This is a stopwatch in Russian. Accuracy depends on processor clock speed

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions