WMI를 사용하여 일시 중단 이벤트 수신 대기
다음 코드를 사용하여 MSBTS_ServiceInstanceSuspendedEvent 수신 대기합니다.
using System.Management;
static public void ListenForSvcInstSuspendEvent()
{
try
{
// Set up an event watcher and a handler for the MSBTS_ServiceInstanceSuspendedEvent event
ManagementEventWatcher watcher = new ManagementEventWatcher( new ManagementScope("root\\MicrosoftBizTalkServer"),
new EventQuery("SELECT * FROM MSBTS_ServiceInstanceSuspendedEvent") );
watcher.EventArrived += new EventArrivedEventHandler(MyEventHandler);
// Start watching for MSBTS_ServiceInstanceSuspendedEvent events
watcher.Start();
while (true)
{
System.Threading.Thread.Sleep(1000);
}
}
catch (Exception excep)
{
Console.WriteLine("Error: " + excep.Message);
}
}
static public void MyEventHandler(object sender, EventArrivedEventArgs e)
{
// Print out the service instance ID and error description upon receiving of the suspend event
Console.WriteLine("A MSBTS_ServiceInstanceSuspendEvent has occurred!");
Console.WriteLine(string.Format("ServiceInstanceID: {0}", e.NewEvent["InstanceID"]));
Console.WriteLine(string.Format("ErrorDescription: {0}", e.NewEvent["ErrorDescription"]));
Console.WriteLine("");
}
Option Explicit
Sub ListenForSvcInstSuspendEvent()
Set objWMIServices = GetObject("WinMgmts:{impersonationLevel=impersonate, (security)}\\.\root\MicrosoftBizTalkServer")
' Create the event sink object that receives the events
Set sinkSuspInst = WScript.CreateObject("WbemScripting.SWbemSink","SINK_INST_")
' Set up the event selection. SINK_INST_OnObjectReady is called when a MSBTS_ServiceInstanceSuspendedEvent occurs
objWMIServices.ExecNotificationQueryAsync sinkSuspInst, "select * from MSBTS_ServiceInstanceSuspendedEvent"
' Infinite loop to wait for event to happen
wscript.echo "Waiting for events..."
while(true)
WScript.Sleep(1000)
wend
End Sub
Sub SINK_INST_OnObjectReady(objObject, objAsyncContext)
wscript.echo "=============================================="
wscript.echo "A MSBTS_ServiceInstanceSuspendEvent has occurred!"
wscript.echo ""
wscript.echo "ServiceInstanceID: " & objObject.InstanceID
wscript.echo ""
wscript.echo "ErrorDescription: " & objObject.ErrorDescription
wscript.echo ""
End Sub
참고 항목
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기