Timer の Elapsed イベントを処理するメソッドを表します。
<Serializable>
Public Delegate Sub ElapsedEventHandler( _ ByVal sender As Object, _ ByVal e As ElapsedEventArgs _)
[C#]
[Serializable]
public delegate void ElapsedEventHandler( object sender, ElapsedEventArgs e);
[C++]
[Serializable]
public __gc __delegate void ElapsedEventHandler( Object* sender, ElapsedEventArgs* e);
[JScript] JScript では、.NET Framework のデリゲートを利用することができます。ただし、独自に定義することはできません。
パラメータ [Visual Basic, C#, C++]
作成するイベント ハンドラは、ElapsedEventHandler クラスのデリゲート定義と同一のパラメータを持つ必要があります。
- sender
イベントのソース。 - e
イベント データを格納している ElapsedEventArgs オブジェクト。
解説
ElapsedEventHandler デリゲートを作成する場合は、イベントを処理するメソッドを指定します。イベントをイベント ハンドラに関連付けるには、デリゲートのインスタンスをイベントに追加します。デリゲートを削除しない限り、そのイベントが発生すると常にイベント ハンドラが呼び出されます。イベント ハンドラ デリゲートの詳細については、「 イベントとデリゲート 」を参照してください。
使用例
Public Class Timer1
Public Shared Sub Main()
Dim aTimer As New System.Timers.Timer()
AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
' Set the Interval to 5 seconds.
aTimer.Interval = 5000
aTimer.Enabled = True
Console.WriteLine("Press 'q' to quit the sample.")
While Console.Read() <> CInt("q")
End While
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
[C#]
public class Timer1
{
public static void Main()
{
System.Timers.Timer aTimer = new System.Timers.Timer();
aTimer.Elapsed+=new ElapsedEventHandler(OnTimedEvent);
// Set the Interval to 5 seconds.
aTimer.Interval=5000;
aTimer.Enabled=true;
Console.WriteLine("Press \'q\' to quit the sample.");
while(Console.Read()!='q');
}
// Specify what you want to happen when the Elapsed event is raised.
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
Console.WriteLine("Hello World!");
}
}
[C++]
public __gc class Timer1
{
public:
static void Main() {
System::Timers::Timer* aTimer = new System::Timers::Timer;
aTimer->Elapsed += new ElapsedEventHandler(0, Timer1::OnTimedEvent);
// Set the Interval to 5 seconds.
aTimer->Interval=5000;
aTimer->Enabled=true;
}
private:
// Specify what you want to happen when the Elapsed event is raised.
static void OnTimedEvent(Object* /*source*/, ElapsedEventArgs* /*e*/)
{
Console::WriteLine(S"Hello World!");
}
};
int main()
{
Timer1::Main();
Console::WriteLine(S"Press \'q\' to quit the sample.");
while(Console::Read()!='q');
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
名前空間: System.Timers
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
アセンブリ: System (System.dll 内)