ElapsedEventArgs.SignalTime Özellik
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Olayın oluşturulduğu tarihi/saati Elapsed alır.
public:
property DateTime SignalTime { DateTime get(); };
public DateTime SignalTime { get; }
member this.SignalTime : DateTime
Public ReadOnly Property SignalTime As DateTime
Özellik Değeri
Olayın oluşturulduğu zaman Elapsed .
Örnekler
Aşağıdaki örnek, iki saniyede bir (2000 milisaniye) olayını başlatanTimer.Elapsed, Timer olay için bir olay işleyicisi ayarlayan ve zamanlayıcıyı başlatan bir nesnenin örneğini oluşturur. Olay işleyicisi, her yükseltildiğinde özelliğinin ElapsedEventArgs.SignalTime değerini görüntüler.
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
open System.Timers
let onTimedEvent source (e: ElapsedEventArgs) =
printfn $"The Elapsed event was raised at {e.SignalTime}"
// Create a timer and set a two second interval.
let aTimer = new Timer()
aTimer.Interval <- 2000
// Hook up the Elapsed event for the timer.
aTimer.Elapsed.AddHandler onTimedEvent
// Have the timer fire repeated events (true is the default)
aTimer.AutoReset <- true
// Start the timer
aTimer.Enabled <- true
printfn "Press the Enter key to exit the program at any time... "
stdin.ReadLine() |> ignore
// 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
Açıklamalar
Olay Timer.Elapsed bir ThreadPool iş parçacığında oluşturulur, bu nedenle olay işleme yöntemi bir iş parçacığında aynı anda çalıştırılabilir ve yönteme Timer.Stop yönelik bir çağrı başka bir iş parçacığında çalışır. Bu, yöntem çağrıldıktan sonra olayın tetiklenmesine Stop neden Elapsed olabilir. Olay işleme yöntemi, yöntem çağrıldığında zaten yürütülüyor olabileceğinden veya yöntemin çağrıldığı Stop an ile durdurma süresinin kaydedildiği an Stop arasında yürütmeye başlayabileceği için, bu yarış durumu yalnızca özelliği yöntemin çağrıldığı saatle Stop karşılaştırılarak SignalTime engellenemez. Olay işleme yöntemi yürütülürken yöntemini çağıran iş parçacığının Stop devam etmesini önlemek kritikse, sınıfı veya CompareExchange yöntemi gibi Monitor daha sağlam bir eşitleme mekanizması kullanın. yöntemini kullanan CompareExchange kod, yönteminin örneğinde Timer.Stop bulunabilir.