Stopwatch.Stop メソッド
アセンブリ: System (system.dll 内)


一般的な Stopwatch のシナリオでは、Start メソッドを呼び出してから、最終的に Stop メソッドを呼び出し、Elapsed プロパティを使用して経過時間を確認します。
Stop メソッドは、現在の時間間隔の計測を終了します。実行されていない Stopwatch を停止しても、タイマの状態が変更されたり、経過時間のプロパティがリセットされたりすることはありません。
Stopwatch インスタンスが複数の間隔を計測する場合、Stop メソッドは、経過時間の計測を一時停止するのと同じです。後続の Start の呼び出しにより、現在の経過時間の値から時間の計測が再開されます。Stopwatch インスタンスの累積経過時間を消去するには、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.Stop メソッドのページへのリンク