|
| Hi all,
I want to get the status of send port programmatically. When ever
there is a
change in the state (Start, Stop, enlist etc) of the SendPort i need
to get
a message. I tried the code pasted below. But i am getting
an error 0x80131600 (COR_E_APPLICATION). I am using
__InstanceModificationEvent in the c
ode.
Please let me know what i am doing is correct? is there any other way
to get
this events?
using System;
using System.Management;
using System.Xml;
namespace InstanceEvent
{
public class EventWatcherPolling
{
static public void MyEventHandler(object sender,
EventArrivedEventArgs e)
{
try
{
System.Console.WriteLine("Class Name:" +
((ManagementBaseObject)e.NewEvent["TargetInstance"])["Name"]);
}
catch(Exception ex)
{
System.Console.WriteLine("Text from Ex: " + ex.Message);
}
}
public static int Main(string[] args)
{
WqlEventQuery query = new
WqlEventQuery("__InstanceModificationEvent", new TimeSpan(0,0,10),
"TargetInstance ISA \"MSBTS_SendPort\"");
try
{
ManagementEventWatcher watcher = new ManagementEventWatcher(new
ManagementScope("root\\MicrosoftBizTalkServer"), query);
watcher.EventArrived += new
EventArrivedEventHandler(MyEventHandler)
;
watcher.Start();
}
catch (ApplicationException ex)
{
System.Console.WriteLine("Text from APP: " + ex.ToString());
}
System.Console.Read();
return 0;
}
}
}
|
|