C# sleep処理を行う

C#で、Thread.Sleepを使用して、待機時間をつくるサンプルコードを記述してます。
環境
- OS windows10 pro 64bit
- Microsoft Visual Studio Community 2019 Version 16.7.1
Thread.Sleep使い方
Thread.Sleepを使用すると、待機時間をつくることが可能です。
以下は、3秒の待機時間を作成するサンプルコードとなります。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
using System; using System.Threading; namespace testapp { class Program { static void Main(string[] args) { DateTime now; now = DateTime.Now; Console.WriteLine(now.ToString("mm:ss")); // 3秒待機 Thread.Sleep(3000); now = DateTime.Now; Console.WriteLine(now.ToString("mm:ss")); Console.ReadKey(); } } } |
実行結果

-
前の記事
rails6 redisを使用する 2021.02.09
-
次の記事
vscode nugetを使用する 2021.02.09
コメントを書く