using System;
using System.Threading;

class Example
{
    static void Main()
    {
        TimeSpan interval = new TimeSpan(0, 0, 2);

        for (int i = 0; i < 5; i++)
        {
            Console.WriteLine("Sleep for 2 seconds.");
            Thread.Sleep(interval);
        }

        Console.WriteLine("Main thread exits.");
    }
}
/* This example produces the following output:

Sleep for 2 seconds.
Sleep for 2 seconds.
Sleep for 2 seconds.
Sleep for 2 seconds.
Sleep for 2 seconds.
Main thread exits.
 */

每次输出

"Sleep for 2 seconds." 都会停留2秒

相关文章:

  • 2021-06-29
  • 2021-04-23
  • 2021-10-04
  • 2021-07-30
  • 2021-10-28
  • 2022-12-23
  • 2021-12-18
猜你喜欢
  • 2021-06-26
  • 2021-05-24
  • 2021-09-27
相关资源
相似解决方案