ElapsedEventArgs Classe
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Fournit des données pour l’événement Elapsed.
public ref class ElapsedEventArgs : EventArgs
public ref class ElapsedEventArgs sealed : EventArgs
public class ElapsedEventArgs : EventArgs
public sealed class ElapsedEventArgs : EventArgs
type ElapsedEventArgs = class
inherit EventArgs
Public Class ElapsedEventArgs
Inherits EventArgs
Public NotInheritable Class ElapsedEventArgs
Inherits EventArgs
- Héritage
Exemples
L’exemple suivant instancie un objet Timer qui déclenche son événement de Timer.Elapsed toutes les deux secondes (2000 millisecondes), configure un gestionnaire d’événements pour l’événement et démarre le minuteur. Le gestionnaire d’événements affiche la valeur de la propriété ElapsedEventArgs.SignalTime chaque fois qu’elle est déclenchée.
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
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
Constructeurs
ElapsedEventArgs(DateTime) |
Initialise une nouvelle instance de la classe ElapsedEventArgs. |
Propriétés
SignalTime |
Obtient la date/heure à laquelle l’événement Elapsed a été déclenché. |
Méthodes
Equals(Object) |
Détermine si l’objet spécifié est égal à l’objet actuel. (Hérité de Object) |
GetHashCode() |
Sert de fonction de hachage par défaut. (Hérité de Object) |
GetType() |
Obtient la Type de l’instance actuelle. (Hérité de Object) |
MemberwiseClone() |
Crée une copie superficielle du Objectactuel. (Hérité de Object) |
ToString() |
Retourne une chaîne qui représente l’objet actuel. (Hérité de Object) |