Timer.AutoReset プロパティ
アセンブリ: System (system.dll 内)

/** @property */ public boolean get_AutoReset () /** @property */ public void set_AutoReset (boolean value)
指定した間隔が経過するたびに Timer で Elapsed イベントを発生させる場合は true。指定した間隔が経過した後に 1 回だけ Elapsed イベントを発生させる場合は false。既定値は true です。

Start が呼び出された時点で既に Timer が有効になっていた場合、間隔はリセットされます。AutoReset が false の場合は、Start メソッドを呼び出して再びカウントを開始する必要があります。
間隔をリセットした場合は、Elapsed イベントがいつ発生するかに影響します。たとえば、間隔を 5 秒に設定し、Enabled を true に設定した場合は、Enabled を設定した時刻からカウントが開始します。カウントが 3 秒のときに間隔を 10 秒にリセットした場合、最初の Elapsed イベントは Enabled プロパティを true に設定してから 13 秒後に発生します。

10 秒経過すると、コンソールに "Hello World!" と表示する Timer を作成する例を次に示します。
この例では、System.Timers 名前空間を使用します。
' From command line, compile with /r:System.dll Imports System Imports System.Timers Public Class Timer2 Public Shared Sub Main() ' Normally, the timer is declared at the class level, so ' that it doesn't go out of scope when the method ends. ' In this example, the timer is needed only while Main ' is executing. However, KeepAlive must be used at the ' end of Main, to prevent the JIT compiler from allowing ' aggressive garbage collection to occur before Main ' ends. ' ' Create a timer with a ten second interval. Dim aTimer As New System.Timers.Timer(10000) ' Hook up the event handler for the Elapsed event. AddHandler aTimer.Elapsed, AddressOf OnTimedEvent ' Only raise the event the first time Interval elapses. aTimer.AutoReset = False aTimer.Enabled = True Console.WriteLine("Press the Enter key to exit the program.") Console.ReadLine() ' Keep the timer alive until the end of Main. GC.KeepAlive(aTimer) End Sub ' Specify what you want to happen when the Elapsed event is ' raised. Private Shared Sub OnTimedEvent(source As Object, e As ElapsedEventArgs) Console.WriteLine("Hello World!") End Sub End Class
// From command line, compile with /r:System.dll using System; using System.Timers; public class Timer2 { public static void Main() { // Normally, the timer is declared at the class level, so // that it doesn't go out of scope when the method ends. // In this example, the timer is needed only while Main // is executing. However, KeepAlive must be used at the // end of Main, to prevent the JIT compiler from allowing // aggressive garbage collection to occur before Main // ends. // // Create a timer with a ten second interval. System.Timers.Timer aTimer = new System.Timers.Timer(10000); // Hook up the event handler for the Elapsed event. aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent); // Only raise the event the first time Interval elapses. aTimer.AutoReset = false; aTimer.Enabled = true; Console.WriteLine("Press the Enter key to exit the program."); Console.ReadLine(); // Keep the timer alive until the end of Main. GC.KeepAlive(aTimer); } // Specify what you want to happen when the Elapsed event is // raised. private static void OnTimedEvent(object source, ElapsedEventArgs e) { Console.WriteLine("Hello World!"); } }
#using <system.dll> using namespace System; using namespace System::Timers; public ref class Timer2 { public: static void Main() { // Normally, the timer is declared at the class level, so // that it doesn't go out of scope when the method ends. // In this example, the timer is needed only while Demo // is executing. However, KeepAlive must be used at the // end of Demo, to prevent the JIT compiler from allowing // aggressive garbage collection to occur before Demo // ends. // // Create a new Timer with Interval set to 10 seconds. System::Timers::Timer^ aTimer = gcnew System::Timers::Timer( 10000 ); // Hook up the event handler for the Elapsed event. aTimer->Elapsed += gcnew ElapsedEventHandler( OnTimedEvent ); // Only raise the event the first time Interval elapses. aTimer->AutoReset = false; aTimer->Enabled = true; Console::WriteLine("Press the Enter key to exit the program."); Console::ReadLine(); // Keep the timer alive until the end of the Demo method. GC::KeepAlive(aTimer); } private: // Specify what you want to happen when the Elapsed event is // raised. static void OnTimedEvent( Object^ /*source*/, ElapsedEventArgs^ /*e*/ ) { Console::WriteLine( "Hello World!" ); } }; int main() { Timer2::Main(); }

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からTimer.AutoReset プロパティを検索する場合は、下記のリンクをクリックしてください。

- Timer.AutoReset プロパティのページへのリンク