public void OnWindowClosing(object sender, CancelEventArgs cancelEventArgs) { _notifierIcon.Dispose(); _watcherWindow?.Close(); _configWindow?.Close(); if (Global.ItemWebSocket != null) { Global.ItemWebSocket.Close(); } if (Global.WTWebsocket != null) { if (_startWatch != null || _stopWatch != null && Global.WTWebsocket.IsAlive) { Global.WTWebsocket.Send(Utils.SetWebsocketStatusString(Status.Offline)); Global.CurrentExpectedState = Status.Offline; } Global.WTWebsocket.Close(); } _startWatch?.Stop(); _stopWatch?.Stop(); NotificationManager.Notifier.Dispose(); Application.Exit(); }
private void StopInternal() { _systemWatcher.EventArrived -= _systemWatcher_EventArrived; _systemWatcher?.Stop(); _appWatcher.EventArrived -= _appWatcher_EventArrived; _appWatcher?.Stop(); }
public static void Detach() { SystemEvents.PowerModeChanged -= PowerModeChanged; SystemEvents.DisplaySettingsChanged -= DisplaySettingsChanged; usbEventWatcher?.Stop(); usbEventWatcher?.Dispose(); }
/// <summary> /// Creates a watcher that observed if a new removable device is added /// </summary> private void CreateDriveAddWatcher() { var scope = new ManagementScope("root\\CIMV2") { Options = { EnablePrivileges = true } }; try { var q = new WqlEventQuery { EventClassName = "__InstanceCreationEvent", WithinInterval = new TimeSpan(0, 0, 1), Condition = "TargetInstance ISA 'Win32_DiskDrive'", }; InsertManagementEventWatcher = new ManagementEventWatcher(scope, q); InsertManagementEventWatcher.Start(); InsertManagementEventWatcher.EventArrived += ExtractDeviceInformation; } catch (Exception) { InsertManagementEventWatcher?.Stop(); } }
/// <summary> /// Initializes a new instance of the <see cref="Program"/> class. /// </summary> public Program() { try { // Your query goes below; "KeyPath" is the key in the registry that you // want to monitor for changes. Make sure you escape the \ character. WqlEventQuery query = new WqlEventQuery( "SELECT * FROM RegistryValueChangeEvent WHERE " + "Hive = 'HKEY_LOCAL_MACHINE'" + @"AND KeyPath = 'SOFTWARE\\Microsoft\\.NETFramework' AND ValueName='InstallRoot'"); ManagementEventWatcher watcher = new ManagementEventWatcher(query); Console.WriteLine("Waiting for an event..."); // Set up the delegate that will handle the change event. watcher.EventArrived += new EventArrivedEventHandler(HandleEvent); // Start listening for events. watcher.Start(); // Do something while waiting for events. In your application, // this would just be continuing business as usual. System.Threading.Thread.Sleep(100000000); // Stop listening for events. watcher.Stop(); } catch (ManagementException managementException) { Console.WriteLine("An error occurred: " + managementException.Message); } }
/// <summary> /// Creates a watcher that observed if a removable device is removed /// </summary> private void CreateDriveRemoveWatcher() { var scope = new ManagementScope("root\\CIMV2") { Options = { EnablePrivileges = true } }; try { var q = new WqlEventQuery { EventClassName = "__InstanceDeletionEvent", WithinInterval = new TimeSpan(0, 0, 1), Condition = "TargetInstance ISA 'Win32_LogicalDisk'" }; RemoveManagementEventWatcher = new ManagementEventWatcher(scope, q); RemoveManagementEventWatcher.Start(); RemoveManagementEventWatcher.EventArrived += ClearDriveInformation; } catch (Exception e) { Console.WriteLine(e.Message); RemoveManagementEventWatcher?.Stop(); } }
/// <summary> /// Освобождает используемые ресурсы /// </summary> public void Dispose() { _mewDiskDriveToPartitionCreation?.Stop(); _mewDiskDriveToPartitionCreation?.Dispose(); _mewDiskDriveToPartitionDeletion?.Stop(); _mewDiskDriveToPartitionDeletion?.Dispose(); _isDisposed = true; }
protected override Task CloseAsync() { Stop(); startWatch?.Stop(); stopWatch?.Stop(); return(base.CloseAsync()); }
protected virtual void Dispose(bool disposing) { if (!disposing) { return; } _managementEventWatcher?.Stop(); _managementEventWatcher?.Dispose(); }
public void Dispose() { arrival?.Stop(); removal?.Stop(); arrival?.Dispose(); removal?.Dispose(); arrival = null; removal = null; }
protected override Task OnClosingAsync() { _isAppClosing = true; Stop(); startWatch?.Stop(); stopWatch?.Stop(); return(base.OnClosingAsync()); }
public static void RemoveInstanceChange() { InstanceCreationEvent?.Stop(); InstanceDeletionEvent?.Stop(); InstanceCreationEvent?.Dispose(); InstanceDeletionEvent?.Dispose(); InstanceCreationEvent = null; InstanceDeletionEvent = null; }
/// <summary> /// 移除并销毁 由 <see cref="ListenInstanceChange(string, TimeSpan, Action{ManagementBaseObject}, log4net.ILog)"/> 创建的监听。 /// <para>移除监听 "__InstanceModificationEvent" 事件</para> /// </summary> public static void RemoveInstanceModification() { if (InstanceModificationEvent == null) { return; } SpaceCGUtils.RemoveAnonymousEvents(InstanceModificationEvent, "EventArrived"); InstanceModificationEvent?.Stop(); InstanceModificationEvent?.Dispose(); InstanceModificationEvent = null; }
public override void Stop() { try { _processStartEvent?.Stop(); _processStopEvent?.Stop(); } catch { // ignored } }
public void Dispose() { try { _watcher?.Stop(); _watcher?.Dispose(); } catch (Exception ex) { Logger.Error($"Failed to stop the system watcher: {ex.Message}"); } }
/// <summary> /// 停止USB设备监控 /// </summary> public void Stop() { InsertEvent?.Stop(); InsertEvent = null; RemoveEvent?.Stop(); RemoveEvent = null; USBInsertEvent = null; USBRemoveEvent = null; Token.Cancel(); }
/// <summary> /// Shutdown the Warden service /// </summary> public static void Stop() { _processStartEvent?.Stop(); _processStopEvent?.Stop(); if (Options.CleanOnExit) { Parallel.ForEach(ManagedProcesses.Values, managed => { managed.Kill(); }); } ManagedProcesses.Clear(); }
/// <summary> Class constructor, initialize accessbridge aswell as the process watcher and the events </summary> public Linker() { //Initialize the watcher InitializeWatcher(); //Initialize events OnGamePaired += (hwnd) => { watcher?.Stop(); IsLookingForGame = false; }; OnGameExited += WaitForGameToLoad; }
/// <summary> /// Shutdown the Warden service /// </summary> public static void Stop() { _processStartEvent?.Stop(); _processStopEvent?.Stop(); if (_killTressOnExit) { foreach (var managed in ManagedProcesses.Values) { managed.Kill(); } } ManagedProcesses.Clear(); }
//protected override void OnResize(EventArgs e) //{ // base.OnResize(e); // if (WindowState == FormWindowState.Minimized) // { // // this.ShowInTaskbar = false; // Hide(); // } //} //private void ApplicationMainForm_Resize(object sender, EventArgs e) //{ // if (this.WindowState == FormWindowState.Minimized) // { // // this.ShowInTaskbar = false; // Hide(); // } //} protected override void OnFormClosing(FormClosingEventArgs e) { if (e.CloseReason == CloseReason.UserClosing) { ShowInTaskbar = false; Hide(); e.Cancel = true; } else { _processStopEventWatcher?.Stop(); base.OnFormClosing(e); } }
public void Stop() { if (_watcher != null) { _watcher?.Stop(); _watcher.EventArrived -= new EventArrivedEventHandler(Watcher_EventArrived); _watcher = null; } if (_comConnection != null) { _comConnection.Disconnect(); _comConnection.RfidReceived -= ComConnection_RfidReceived; _comConnection = null; } }
/// <summary> /// 移除并销毁 由 <see cref="ListenInstanceChange(string, TimeSpan, Action{ManagementBaseObject}, log4net.ILog)"/> 创建的监听。 /// <para>移除监听 "__InstanceCreationEvent" AND "__InstanceDeletionEvent" 事件</para> /// </summary> public static void RemoveInstanceChange() { if (InstanceCreationEvent != null) { SpaceCGUtils.RemoveAnonymousEvents(InstanceCreationEvent, "EventArrived"); InstanceCreationEvent?.Stop(); InstanceCreationEvent?.Dispose(); } if (InstanceDeletionEvent != null) { SpaceCGUtils.RemoveAnonymousEvents(InstanceDeletionEvent, "EventArrived"); InstanceDeletionEvent?.Stop(); InstanceDeletionEvent?.Dispose(); } InstanceCreationEvent = null; InstanceDeletionEvent = null; }
/// <summary> /// Shutdown the Warden service /// </summary> public static void Stop() { Logger?.Info("Stopping Warden"); _processStartEvent?.Stop(); _processStartEvent?.Dispose(); _processStopEvent?.Stop(); _processStopEvent?.Dispose(); if (Options?.CleanOnExit == true) { Parallel.ForEach(ManagedProcesses.Values, managed => { managed.Kill(); }); } _connectionScope = null; ManagedProcesses.Clear(); CreationThread?.Join(); DestructionThread?.Join(); }
private void CleanUp() { _watcher?.Stop(); _watcher?.Dispose(); _watcher = null; }
public void Dispose() { _watcher?.Stop(); }
/// <summary> /// If this method isn't called, an InvalidComObjectException will be thrown (like below): /// System.Runtime.InteropServices.InvalidComObjectException was unhandled ///Message=COM object that has been separated from its underlying RCW cannot be used. ///Source=mscorlib ///StackTrace: /// at System.StubHelpers.StubHelpers.StubRegisterRCW(Object pThis, IntPtr pThread) /// at System.Management.IWbemServices.CancelAsyncCall_(IWbemObjectSink pSink) /// at System.Management.SinkForEventQuery.Cancel() /// at System.Management.ManagementEventWatcher.Stop() /// at System.Management.ManagementEventWatcher.Finalize() ///InnerException: /// </summary> public static void CleanUp() { arrival.Stop(); removal.Stop(); }
private void StopWatcher() { _processStartWatcher.Stop(); _processStopWatcher.Stop(); }
public void Stop() { managementEventWatcher1.Stop(); managementEventWatcher2.Stop(); }
// Stop linsten to port change event public void Stop() { arrival.Stop(); removal.Stop(); }
public void Stop() { watcher.Stop(); }
public void Stop() { _managementEventWatcher.Stop(); }