Stopwatch.Start メソッド
アセンブリ: System (system.dll 内)
構文
解説
一般的な Stopwatch のシナリオでは、Start メソッドを呼び出してから、最終的に Stop メソッドを呼び出し、Elapsed プロパティを使用して経過時間を確認します。
Stopwatch タイマが開始されると、インスタンスが停止またはリセットされるまで、経過したタイマ刻みの現在の間隔が計測されます。既に実行中の Stopwatch を開始しても、タイマの状態が変更されたり、経過時間のプロパティがリセットされたりすることはありません。
Stopwatch インスタンスが複数の間隔を計測する場合、Start メソッドは、現在の経過時間の値から時間の計測を再開します。Stopwatch インスタンスは、リセットされるまで複数の時間間隔の累積経過時間を計算および保持します。Stopwatch インスタンスの累積経過時間を消去するには、Start を呼び出す前に Reset メソッドを使用します。
Stopwatch クラスを使用して、Windows フォーム アプリケーションで開始、停止、リセット、およびラップタイムの各ボタンを実装する例を次に示します。このコード例は、Stopwatch クラスのトピックで取り上げているコード例の一部分です。
If stopWatch.IsRunning Then ' Stop the timer; show the start and reset buttons. stopWatch.Stop() buttonStartStop.Text = "Start" buttonLapReset.Text = "Reset" Else ' Start the timer; show the stop and lap buttons. stopWatch.Start() buttonStartStop.Text = "Stop" buttonLapReset.Text = "Lap" labelLap.Visible = False labelLapPrompt.Visible = False End If
if (stopWatch.IsRunning) { // Stop the timer; show the start and reset buttons. stopWatch.Stop(); buttonStartStop.Text = "Start"; buttonLapReset.Text = "Reset"; } else { // Start the timer; show the stop and lap buttons. stopWatch.Start(); buttonStartStop.Text = "Stop"; buttonLapReset.Text = "Lap"; labelLap.Visible = false; labelLapPrompt.Visible = false; }
if ( stopWatch->IsRunning ) { // Stop the timer; show the start and reset buttons. stopWatch->Stop(); buttonStartStop->Text = "Start"; buttonLapReset->Text = "Reset"; } else { // Start the timer; show the stop and lap buttons. stopWatch->Start(); buttonStartStop->Text = "Stop"; buttonLapReset->Text = "Lap"; labelLap->Visible = false; labelLapPrompt->Visible = false;
if (stopWatch.get_IsRunning()) { // Stop the timer; show the start and reset buttons. stopWatch.Stop(); buttonStartStop.set_Text("Start"); buttonLapReset.set_Text("Reset"); } else { // Start the timer; show the stop and lap buttons. stopWatch.Start(); buttonStartStop.set_Text("Stop"); buttonLapReset.set_Text("Lap"); labelLap.set_Visible(false); labelLapPrompt.set_Visible(false); }
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
- Stopwatch.Start メソッドのページへのリンク