EventWatcherOptions.BlockSize Property
Assembly: System.Management (in system.management.dll)
/** @property */ public int get_BlockSize () /** @property */ public void set_BlockSize (int value)
public function get BlockSize () : int public function set BlockSize (value : int)
Not applicable.
Property Value
Returns an Int32 value indicating the block size for a block of operations.Property Value
The default value is 1.
.NET Framework Security
Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.
The following example shows how the client receives notification when an instance of Win32_Process is created because the event class is __InstanceCreationEvent. For more information, see the Windows Management Instrumentation documentation in the MSDN Library at http://msdn.microsoft.com/library. The client receives events synchronously by calling the WaitForNextEvent method. This example can be tested by starting a process, such as Notepad, while the example code is running.
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; } }
Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.