String mePath = "\\\\localhost\\root\\MicrosoftNLB" ;
ManagementEventWatcher watcher1 = new ManagementEventWatcher(mePath, "SELECT * FROM MicrosoftNLB_NodeControlEvent" );
watcher1.EventArrived += new EventArrivedEventHandler(watcher_NodeControlEventArrived);
watcher1.Options.Timeout = new TimeSpan (0, 0, 1);
watcher1.Start(); //need Stop!!!!!!!
* This source code was highlighted with Source Code Highlighter .
String mePath = "\\\\localhost\\root\\MicrosoftNLB" ;
ManagementEventWatcher watcher1 = new ManagementEventWatcher(mePath, "SELECT * FROM MicrosoftNLB_NodeControlEvent" );
watcher1.EventArrived += new EventArrivedEventHandler(watcher_NodeControlEventArrived);
watcher1.Options.Timeout = new TimeSpan (0, 0, 1);
watcher1.Start(); //need Stop!!!!!!!
* This source code was highlighted with Source Code Highlighter .
static void watcher_NodeControlEventArrived( object sender, EventArrivedEventArgs e)
{
//http://msdn.microsoft.com/en-us/library/bb736304(VS.85).aspx
ManagementEventWatcher watcher = (ManagementEventWatcher)sender;
Console .WriteLine(watcher.Query.QueryString.ToString());
PropertyData property;
if ((property = e.NewEvent.Properties[ "Id" ]) != null )
{
Console .WriteLine(property.Name + ": " + property.Value);
}
if ((property = e.NewEvent.Properties[ "InstanceName" ]) != null )
{
Console .WriteLine(property.Name + ": " + property.Value);
}
if ((property = e.NewEvent.Properties[ "Active" ]) != null )
{
Console .WriteLine(property.Name + ": " + property.Value);
}
if ((property = e.NewEvent.Properties[ "AdapterGuid" ]) != null )
{
Console .WriteLine(property.Name + ": " + property.Value);
}
if ((property = e.NewEvent.Properties[ "ClusterIPAddress" ]) != null )
{
Console .WriteLine(property.Name + ": " + property.Value);
}
if ((property = e.NewEvent.Properties[ "HostPriority" ]) != null )
{
Console .WriteLine(property.Name + ": " + property.Value);
}
}
* This source code was highlighted with Source Code Highlighter .
static void watcher_NodeControlEventArrived( object sender, EventArrivedEventArgs e)
{
//http://msdn.microsoft.com/en-us/library/bb736304(VS.85).aspx
ManagementEventWatcher watcher = (ManagementEventWatcher)sender;
Console .WriteLine(watcher.Query.QueryString.ToString());
PropertyData property;
if ((property = e.NewEvent.Properties[ "Id" ]) != null )
{
Console .WriteLine(property.Name + ": " + property.Value);
}
if ((property = e.NewEvent.Properties[ "InstanceName" ]) != null )
{
Console .WriteLine(property.Name + ": " + property.Value);
}
if ((property = e.NewEvent.Properties[ "Active" ]) != null )
{
Console .WriteLine(property.Name + ": " + property.Value);
}
if ((property = e.NewEvent.Properties[ "AdapterGuid" ]) != null )
{
Console .WriteLine(property.Name + ": " + property.Value);
}
if ((property = e.NewEvent.Properties[ "ClusterIPAddress" ]) != null )
{
Console .WriteLine(property.Name + ": " + property.Value);
}
if ((property = e.NewEvent.Properties[ "HostPriority" ]) != null )
{
Console .WriteLine(property.Name + ": " + property.Value);
}
}
* This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/88345/
All Articles