EventWatcherOptions.BlockSize Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan atau mengatur ukuran blok untuk operasi blok. Saat menunggu peristiwa, nilai ini menentukan berapa banyak peristiwa yang harus ditunggu sebelum kembali.
public:
property int BlockSize { int get(); void set(int value); };
public int BlockSize { get; set; }
member this.BlockSize : int with get, set
Public Property BlockSize As Integer
Nilai Properti
Nilai bilangan bulat yang menunjukkan ukuran blok untuk blok operasi.
Contoh
Contoh berikut menunjukkan bagaimana klien menerima pemberitahuan saat instans Win32_Process dibuat karena kelas peristiwa __InstanceCreationEvent. Untuk informasi selengkapnya, lihat dokumentasi Instrumentasi Manajemen Windows . Klien menerima peristiwa secara sinkron dengan memanggil WaitForNextEvent metode . Contoh ini dapat diuji dengan memulai proses, seperti Notepad, saat kode contoh sedang berjalan.
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;
// return after 1 event is received
eventOptions.BlockSize = 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
Dim eventOptions As New EventWatcherOptions
eventOptions.Timeout = System.TimeSpan.MaxValue
' return after 1 event is received
eventOptions.BlockSize = 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
Keterangan
Nilai Properti
Nilai default adalah 1.
.NET Framework Security
Kepercayaan penuh untuk penelepon segera. Anggota ini tidak dapat digunakan oleh kode tepercaya sebagian. Untuk informasi selengkapnya, lihat Menggunakan Pustaka dari Kode Tepercaya Sebagian.