ElapsedEventArgs.SignalTime ElapsedEventArgs.SignalTime ElapsedEventArgs.SignalTime ElapsedEventArgs.SignalTime Property

정의

Elapsed 이벤트가 발생한 날짜/시간을 가져옵니다.Gets the date/time when the Elapsed event was raised.

public:
 property DateTime SignalTime { DateTime get(); };
public DateTime SignalTime { get; }
member this.SignalTime : DateTime
Public ReadOnly Property SignalTime As DateTime

속성 값

Elapsed 이벤트가 발생한 시간입니다.The time the Elapsed event was raised.

예제

다음 예제에서는 Timer 발생 하는 개체는 Timer.Elapsed 2 초 (2000 밀리초) 마다 이벤트를 이벤트에 대 한 이벤트 처리기를 설정 하 고 타이머를 시작 합니다.The following example instantiates a Timer object that fires its Timer.Elapsed event every two seconds (2000 milliseconds), sets up an event handler for the event, and starts the timer. 값을 표시 하는 이벤트 처리기는 ElapsedEventArgs.SignalTime 될 때마다 발생 하는 속성입니다.The event handler displays the value of the ElapsedEventArgs.SignalTime property each time it is raised.

using namespace System;
using namespace System::Timers;

public ref class Example
{
private:
    static System::Timers::Timer^ aTimer;

public:
    static void Demo()
    {
        // Create a timer and set a two second interval.
        aTimer = gcnew System::Timers::Timer();
        aTimer->Interval = 2000;

        // Hook up the Elapsed event for the timer. 
        aTimer->Elapsed += gcnew System::Timers::ElapsedEventHandler(Example::OnTimedEvent);

        // Have the timer fire repeated events (true is the default)
        aTimer->AutoReset = true;

        // Start the timer
        aTimer->Enabled = true;

        Console::WriteLine("Press the Enter key to exit the program at any time... ");
        Console::ReadLine();
    }

private:
    static void OnTimedEvent(Object^ source, System::Timers::ElapsedEventArgs^ e)
    {
        Console::WriteLine("The Elapsed event was raised at {0}", e->SignalTime);
    }
};

int main()
{
    Example::Demo();
}
// The example displays output like the following: 
//       Press the Enter key to exit the program at any time... 
//       The Elapsed event was raised at 5/20/2015 8:48:58 PM 
//       The Elapsed event was raised at 5/20/2015 8:49:00 PM 
//       The Elapsed event was raised at 5/20/2015 8:49:02 PM 
//       The Elapsed event was raised at 5/20/2015 8:49:04 PM 
//       The Elapsed event was raised at 5/20/2015 8:49:06 PM 

using System;
using System.Timers;

public class Example
{
    private static Timer aTimer;

    public static void Main()
    {
        // Create a timer and set a two second interval.
        aTimer = new System.Timers.Timer();
        aTimer.Interval = 2000;

        // Hook up the Elapsed event for the timer. 
        aTimer.Elapsed += OnTimedEvent;

        // Have the timer fire repeated events (true is the default)
        aTimer.AutoReset = true;

        // Start the timer
        aTimer.Enabled = true;

        Console.WriteLine("Press the Enter key to exit the program at any time... ");
        Console.ReadLine();
    }

    private static void OnTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
    {
        Console.WriteLine("The Elapsed event was raised at {0}", e.SignalTime);
    }
}
// The example displays output like the following: 
//       Press the Enter key to exit the program at any time... 
//       The Elapsed event was raised at 5/20/2015 8:48:58 PM 
//       The Elapsed event was raised at 5/20/2015 8:49:00 PM 
//       The Elapsed event was raised at 5/20/2015 8:49:02 PM 
//       The Elapsed event was raised at 5/20/2015 8:49:04 PM 
//       The Elapsed event was raised at 5/20/2015 8:49:06 PM 
Imports System.Timers

Public Module Example
    Private aTimer As Timer

    Public Sub Main()
        ' Create a timer and set a two second interval.
        aTimer = New System.Timers.Timer()
        aTimer.Interval = 2000

        ' Hook up the Elapsed event for the timer.  
        AddHandler aTimer.Elapsed, AddressOf OnTimedEvent

        ' Have the timer fire repeated events (true is the default)
        aTimer.AutoReset = True

        ' Start the timer
        aTimer.Enabled = True

        Console.WriteLine("Press the Enter key to exit the program at any time... ")
        Console.ReadLine()
    End Sub

    Private Sub OnTimedEvent(source As Object, e As System.Timers.ElapsedEventArgs)
        Console.WriteLine("The Elapsed event was raised at {0}", e.SignalTime)
    End Sub
End Module
' The example displays output like the following: 
'       Press the Enter key to exit the program at any time... 
'       The Elapsed event was raised at 5/20/2015 8:48:58 PM 
'       The Elapsed event was raised at 5/20/2015 8:49:00 PM 
'       The Elapsed event was raised at 5/20/2015 8:49:02 PM 
'       The Elapsed event was raised at 5/20/2015 8:49:04 PM 
'       The Elapsed event was raised at 5/20/2015 8:49:06 PM 

설명

Timer.Elapsed 에서 이벤트가 발생을 ThreadPool 스레드, 이벤트 처리 메서드 스레드와 동시에 실행할 수 있도록 하는 시간에 대 한 호출을 Timer.Stop 메서드를 다른 스레드에서 실행 합니다.The Timer.Elapsed event is raised on a ThreadPool thread, so the event-handling method might run on one thread at the same time that a call to the Timer.Stop method runs on another thread. 이 발생할 수 있습니다 합니다 Elapsed 후 발생 한 이벤트를 Stop 메서드가 호출 됩니다.This might result in the Elapsed event being raised after the Stop method is called. 비교 하 여이 경합 상태를 방지할 수 없습니다는 SignalTime 시간을 사용 하 여 속성 때 합니다 Stop 이벤트 처리 메서드에서 이미 실행 중일 수 있습니다 시기 때문에 메서드가 호출 되는 Stop 메서드를 호출 하거나 시작할 수 있습니다 순간 사이 실행 하면는 Stop 메서드는 및 중지 시간 저장 될 때 현재 합니다.This race condition cannot be prevented simply by comparing the SignalTime property with the time when the Stop method is called, because the event-handling method might already be executing when the Stop method is called, or might begin executing between the moment when the Stop method is called and the moment when the stop time is saved. 호출 하는 스레드를 방지 하기 위해 중요 한 경우는 Stop 이벤트 처리 메서드에서 여전히 실행 되는 동안 진행 되 고 메서드에서 같은 보다 강력한 동기화 메커니즘을 사용 합니다 Monitor 클래스 또는 CompareExchange 메서드.If it is critical to prevent the thread that calls the Stop method from proceeding while the event-handling method is still executing, use a more robust synchronization mechanism such as the Monitor class or the CompareExchange method. 사용 하는 코드를 CompareExchange 예제에서 메서드를 찾을 수는 Timer.Stop 메서드.Code that uses the CompareExchange method can be found in the example for the Timer.Stop method.

적용 대상

추가 정보