Created
April 1, 2024 21:40
-
-
Save jTakasuRyuji/e46687df6e865567e2a3187d1b9b8780 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Diagnostics; | |
| class Program | |
| { | |
| static async Task Main(string[] args) | |
| { | |
| int countdownSeconds = 60; // カウントダウンする秒数 | |
| // ストップウォッチを開始 | |
| Stopwatch stopwatch = Stopwatch.StartNew(); | |
| // カウントダウン | |
| while (countdownSeconds > 0) | |
| { | |
| // 現在の経過時間を取得 | |
| long elapsedMilliseconds = stopwatch.ElapsedMilliseconds; | |
| // 次の秒のタイムスタンプを計算 | |
| long nextSecondTimestamp = (elapsedMilliseconds / 1000 + 1) * 1000; | |
| int MillisecondsDelay = (int)(nextSecondTimestamp - elapsedMilliseconds); | |
| // 次の秒まで待機 | |
| await Task.Delay(MillisecondsDelay); | |
| // 秒数を減算して表示 | |
| countdownSeconds--; | |
| Console.WriteLine($"残り時間: {countdownSeconds}秒 / Task.Delay({MillisecondsDelay}ms)"); | |
| } | |
| Console.WriteLine("タイマー終了"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment