EventArrivedEventHandler 委托
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示用来处理 EventArrived 事件的方法。
public delegate void EventArrivedEventHandler(System::Object ^ sender, EventArrivedEventArgs ^ e);
public delegate void EventArrivedEventHandler(object sender, EventArrivedEventArgs e);
type EventArrivedEventHandler = delegate of obj * EventArrivedEventArgs -> unit
Public Delegate Sub EventArrivedEventHandler(sender As Object, e As EventArrivedEventArgs)
参数
- sender
- Object
要为其调用此方法的对象的实例。
EventArrivedEventArgs,指定调用事件的原因。
示例
以下异步示例设置 WMI 计时器以每秒引发一个事件,并在不再需要时将其删除。 定义ManagementEventWatcher多个.NET Framework传递 WMI 事件时引发的事件。 委托被附加到这些事件,以处理传入的数据。
using System;
using System.Management;
// This example shows asynchronous consumption of events.
// In this example you are listening for timer events.
// The first part of the example sets up the timer.
public class EventWatcherAsync
{
public EventWatcherAsync()
{
// Set up a timer to raise events every 1 second
//=============================================
ManagementClass timerClass =
new ManagementClass("__IntervalTimerInstruction");
ManagementObject timer = timerClass.CreateInstance();
timer["TimerId"] = "Timer1";
timer["IntervalBetweenEvents"] = 1000;
timer.Put();
// Set up the event consumer
//==========================
// Create event query to receive timer events
WqlEventQuery query =
new WqlEventQuery("__TimerEvent",
"TimerId=\"Timer1\"");
// Initialize an event watcher and
// subscribe to timer events
ManagementEventWatcher watcher =
new ManagementEventWatcher(query);
// Set up a listener for events
watcher.EventArrived +=
new EventArrivedEventHandler(
this.HandleEvent);
// Start listening
watcher.Start();
// Do something in the meantime
System.Threading.Thread.Sleep(10000);
// Stop listening
watcher.Stop();
}
private void HandleEvent(object sender,
EventArrivedEventArgs e)
{
Console.WriteLine("Event arrived !");
}
public static void Main(string[] args)
{
// start the event watcher
EventWatcherAsync eventWatcher = new
EventWatcherAsync();
}
}
Imports System.Management
' This example shows asynchronous consumption of events.
' In this example you are listening for timer events.
' The first part of the example sets up the timer.
Public Class EventWatcherAsync
Public Sub New()
' Set up a timer to raise events every 1 second
'=============================================
Dim timerClass As New ManagementClass( _
"__IntervalTimerInstruction")
Dim timer As ManagementObject = _
timerClass.CreateInstance()
timer("TimerId") = "Timer1"
timer("IntervalBetweenEvents") = 1000
timer.Put()
' Set up the event consumer
'==========================
' Create event query to receive timer events
Dim query As New WqlEventQuery("__TimerEvent", _
"TimerId=""Timer1""")
' Initialize an event watcher and subscribe to
' events that match this query
Dim watcher As New ManagementEventWatcher(query)
' Set up a listener for events
AddHandler watcher.EventArrived, _
AddressOf Me.HandleEvent
' Start listening
watcher.Start()
' Do something in the meantime
System.Threading.Thread.Sleep(10000)
' Stop listening
watcher.Stop()
End Sub
Private Sub HandleEvent(ByVal sender As Object, _
ByVal e As EventArrivedEventArgs)
Console.WriteLine("Event arrived !")
End Sub
Public Overloads Shared Function _
Main(ByVal args() As String) As Integer
'start the event watcher
Dim eventWatcher As New EventWatcherAsync
Return 0
End Function
End Class
扩展方法
GetMethodInfo(Delegate) |
获取指示指定委托表示的方法的对象。 |