//******************************************** //Start //******************************************** /// <summary> /// <para>Subscribes to events with the given query and delivers /// them, asynchronously, through the <see cref='System.Management.ManagementEventWatcher.EventArrived'/> event.</para> /// </summary> public void Start() { Initialize(); // Cancel any current event query Stop(); // Submit a new query SecurityHandler securityHandler = Scope.GetSecurityHandler(); IWbemServices wbemServices = scope.GetIWbemServices(); try { sink = new SinkForEventQuery(this, options.Context, wbemServices); if (sink.Status < 0) { Marshal.ThrowExceptionForHR(sink.Status, WmiNetUtilsHelper.GetErrorInfo_f()); } // For async event queries we should ensure 0 flags as this is // the only legal value int status = scope.GetSecuredIWbemServicesHandler(wbemServices).ExecNotificationQueryAsync_( query.QueryLanguage, query.QueryString, 0, options.GetContext(), sink.Stub); if (status < 0) { if (sink != null) { sink.ReleaseStub(); sink = null; } if ((status & 0xfffff000) == 0x80041000) { ManagementException.ThrowWithExtendedInfo((ManagementStatus)status); } else { Marshal.ThrowExceptionForHR(status, WmiNetUtilsHelper.GetErrorInfo_f()); } } } finally { securityHandler.Reset(); } }
//******************************************** //Start //******************************************** /// <summary> /// <para>Subscribes for events with the given query and delivers them asynchronously, through the EventArrived event.</para> /// </summary> public void Start() { Initialize(); // Cancel any current event query Stop(); SecurityHandler securityHandler = Scope.GetSecurityHandler(); int status = (int)ManagementStatus.NoError; // Submit a new query try { IWbemServices wbemServices = scope.GetIWbemServices(); sink = new SinkForEventQuery(this, options.GetContext(), wbemServices); // For async event queries we should ensure 0 flags as this is // the only legal value status = wbemServices.ExecNotificationQueryAsync_( query.QueryLanguage, query.QueryString, 0, options.GetContext(), sink.Stub); } catch (Exception e) { // BUGBUG : securityHandler.Reset()? if (sink != null) // BUGBUG : This looks dangerous { sink.ReleaseStub(); sink = null; } ManagementException.ThrowWithExtendedInfo(e); } finally { securityHandler.Reset(); } if ((status & 0xfffff000) == 0x80041000) { ManagementException.ThrowWithExtendedInfo((ManagementStatus)status); } else if ((status & 0x80000000) != 0) { Marshal.ThrowExceptionForHR(status); } }
//******************************************** //Start //******************************************** /// <summary> /// <para>Subscribes to events with the given query and delivers /// them, asynchronously, through the <see cref='System.Management.ManagementEventWatcher.EventArrived'/> event.</para> /// </summary> public void Start() { Initialize (); // Cancel any current event query Stop (); // Submit a new query SecurityHandler securityHandler = Scope.GetSecurityHandler(); IWbemServices wbemServices = scope.GetIWbemServices(); try { sink = new SinkForEventQuery(this, options.Context, wbemServices); if (sink.Status < 0) { Marshal.ThrowExceptionForHR(sink.Status); } // For async event queries we should ensure 0 flags as this is // the only legal value int status = scope.GetSecuredIWbemServicesHandler(wbemServices).ExecNotificationQueryAsync_( query.QueryLanguage, query.QueryString, 0, options.GetContext(), sink.Stub); if (status < 0) { if (sink != null) { sink.ReleaseStub(); sink = null; } if ((status & 0xfffff000) == 0x80041000) ManagementException.ThrowWithExtendedInfo((ManagementStatus)status); else Marshal.ThrowExceptionForHR(status); } } finally { securityHandler.Reset(); } }