EventWatcherOptions Oluşturucular
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 izlemek için sınıfının yeni bir örneğini EventWatcherOptions başlatır.
Aşırı Yüklemeler
EventWatcherOptions() |
Varsayılan değerleri kullanarak olay izlemek için sınıfının yeni bir örneğini EventWatcherOptions başlatır. Bu, parametresiz oluşturucudur. |
EventWatcherOptions(ManagementNamedValueCollection, TimeSpan, Int32) |
Verilen değerlerle sınıfının yeni bir örneğini EventWatcherOptions başlatır. |
EventWatcherOptions()
- Kaynak:
- ManagementOptions.cs
- Kaynak:
- ManagementOptions.cs
- Kaynak:
- ManagementOptions.cs
Varsayılan değerleri kullanarak olay izlemek için sınıfının yeni bir örneğini EventWatcherOptions başlatır. Bu, parametresiz oluşturucudur.
public:
EventWatcherOptions();
public EventWatcherOptions ();
Public Sub New ()
Örnekler
Aşağıdaki örnekte, olay sınıfı __InstanceCreationEvent olduğundan bir Win32_Process örneği oluşturulduğunda istemcinin nasıl bildirim aldığı gösterilmektedir. Daha fazla bilgi için Windows Yönetim Araçları belgelerine bakın. İstemci, yöntemini çağırarak WaitForNextEvent olayları zaman uyumlu olarak alır. Bu örnek, örnek kod çalışırken Not Defteri gibi bir işlem başlatılarak test edilebilir.
using System;
using System.Management;
// This example shows synchronous consumption of events.
// The client is blocked while waiting for events.
public class EventWatcherPolling
{
public static int Main(string[] args)
{
// Create event query to be notified within 1 second of
// a change in a service
string query = "SELECT * FROM" +
" __InstanceCreationEvent WITHIN 1 " +
"WHERE TargetInstance isa \"Win32_Process\"";
// Event options
EventWatcherOptions eventOptions = new
EventWatcherOptions();
eventOptions.Timeout = System.TimeSpan.MaxValue;
// Initialize an event watcher and subscribe to events
// that match this query
ManagementEventWatcher watcher =
new ManagementEventWatcher("root\\CIMV2", query,
eventOptions);
// Block until the next event occurs
// Note: this can be done in a loop if waiting for
// more than one occurrence
Console.WriteLine(
"Open an application (notepad.exe) to trigger an event.");
ManagementBaseObject e = watcher.WaitForNextEvent();
//Display information from the event
Console.WriteLine(
"Process {0} has been created, path is: {1}",
((ManagementBaseObject)e
["TargetInstance"])["Name"],
((ManagementBaseObject)e
["TargetInstance"])["ExecutablePath"]);
//Cancel the subscription
watcher.Stop();
return 0;
}
}
Imports System.Management
' This example shows synchronous consumption of events.
' The client is blocked while waiting for events.
Public Class EventWatcherPolling
Public Overloads Shared Function _
Main(ByVal args() As String) As Integer
' Create event query to be notified within 1 second of
' a change in a service
Dim query As String
query = "SELECT * FROM" & _
" __InstanceCreationEvent WITHIN 1 " & _
"WHERE TargetInstance isa ""Win32_Process"""
' Event options
Dim eventOptions As New EventWatcherOptions
eventOptions.Timeout = System.TimeSpan.MaxValue
' Initialize an event watcher and subscribe to events
' that match this query
Dim watcher As New ManagementEventWatcher( _
"root\CIMV2", query, eventOptions)
' Block until the next event occurs
' Note: this can be done in a loop
' if waiting for more than one occurrence
Console.WriteLine( _
"Open an application (notepad.exe) to trigger an event.")
Dim e As ManagementBaseObject = _
watcher.WaitForNextEvent()
'Display information from the event
Console.WriteLine( _
"Process {0} has created, path is: {1}", _
CType(e("TargetInstance"), _
ManagementBaseObject)("Name"), _
CType(e("TargetInstance"), _
ManagementBaseObject)("ExecutablePath"))
'Cancel the subscription
watcher.Stop()
Return 0
End Function 'Main
End Class
Açıklamalar
.NET Framework Güvenliği
Anında arayanlar için tam güven. Bu üye kısmen güvenilen kodla kullanılamaz. Daha fazla bilgi için bkz. Kısmen Güvenilen Koddan Kitaplıkları Kullanma.
Şunlara uygulanır
EventWatcherOptions(ManagementNamedValueCollection, TimeSpan, Int32)
- Kaynak:
- ManagementOptions.cs
- Kaynak:
- ManagementOptions.cs
- Kaynak:
- ManagementOptions.cs
Verilen değerlerle sınıfının yeni bir örneğini EventWatcherOptions başlatır.
public:
EventWatcherOptions(System::Management::ManagementNamedValueCollection ^ context, TimeSpan timeout, int blockSize);
public EventWatcherOptions (System.Management.ManagementNamedValueCollection context, TimeSpan timeout, int blockSize);
new System.Management.EventWatcherOptions : System.Management.ManagementNamedValueCollection * TimeSpan * int -> System.Management.EventWatcherOptions
Public Sub New (context As ManagementNamedValueCollection, timeout As TimeSpan, blockSize As Integer)
Parametreler
- context
- ManagementNamedValueCollection
Sağlayıcıya geçirilecek sağlayıcıya özgü bilgileri içeren seçenekler bağlam nesnesi.
- timeout
- TimeSpan
Sonraki olayları beklemek için zaman aşımı.
- blockSize
- Int32
Her blokta beklenmesi gereken olay sayısı.
Örnekler
Aşağıdaki örnekte, olay sınıfı __InstanceCreationEvent olduğundan bir Win32_Process örneği oluşturulduğunda istemcinin nasıl bildirim aldığı gösterilmektedir. Daha fazla bilgi için Windows Yönetim Araçları belgelerine bakın. İstemci, yöntemini çağırarak WaitForNextEvent olayları zaman uyumlu olarak alır. Bu örnek, örnek kod çalışırken Not Defteri gibi bir işlem başlatılarak test edilebilir.
using System;
using System.Management;
// This example shows synchronous consumption of events.
// The client is blocked while waiting for events.
public class EventWatcherPolling
{
public static int Main(string[] args)
{
// Create event query to be notified within 1 second of
// a change in a service
string query = "SELECT * FROM" +
" __InstanceCreationEvent WITHIN 1 " +
"WHERE TargetInstance isa \"Win32_Process\"";
// Event options
// blockSize = 1 to receive one event
EventWatcherOptions eventOptions = new
EventWatcherOptions(null, System.TimeSpan.MaxValue,
1);
// Initialize an event watcher and subscribe to events
// that match this query
ManagementEventWatcher watcher =
new ManagementEventWatcher("root\\CIMV2", query,
eventOptions);
// Block until the next event occurs
// Note: this can be done in a loop if waiting for
// more than one occurrence
Console.WriteLine(
"Open an application (notepad.exe) to trigger an event.");
ManagementBaseObject e = watcher.WaitForNextEvent();
//Display information from the event
Console.WriteLine(
"Process {0} has been created, path is: {1}",
((ManagementBaseObject)e
["TargetInstance"])["Name"],
((ManagementBaseObject)e
["TargetInstance"])["ExecutablePath"]);
//Cancel the subscription
watcher.Stop();
return 0;
}
}
Imports System.Management
' This example shows synchronous consumption of events.
' The client is blocked while waiting for events.
Public Class EventWatcherPolling
Public Overloads Shared Function _
Main(ByVal args() As String) As Integer
' Create event query to be notified within 1 second of
' a change in a service
Dim query As String
query = "SELECT * FROM" & _
" __InstanceCreationEvent WITHIN 1 " & _
"WHERE TargetInstance isa ""Win32_Process"""
' Event options
' blockSize = 1 to receive one event
Dim eventOptions As New EventWatcherOptions( _
Nothing, System.TimeSpan.MaxValue, 1)
' Initialize an event watcher and subscribe to events
' that match this query
Dim watcher As New ManagementEventWatcher( _
"root\CIMV2", query, eventOptions)
' Block until the next event occurs
' Note: this can be done in a loop
' if waiting for more than one occurrence
Console.WriteLine( _
"Open an application (notepad.exe) to trigger an event.")
Dim e As ManagementBaseObject = _
watcher.WaitForNextEvent()
'Display information from the event
Console.WriteLine( _
"Process {0} has created, path is: {1}", _
CType(e("TargetInstance"), _
ManagementBaseObject)("Name"), _
CType(e("TargetInstance"), _
ManagementBaseObject)("ExecutablePath"))
'Cancel the subscription
watcher.Stop()
Return 0
End Function 'Main
End Class
Açıklamalar
.NET Framework Güvenliği
Anında arayanlar için tam güven. Bu üye kısmen güvenilen kodla kullanılamaz. Daha fazla bilgi için bkz. Kısmen Güvenilen Koddan Kitaplıkları Kullanma.