There is a class below:
public static void ProcessWatch_Initialize() { try { ManagementScope scope = new ManagementScope("root\\CIMV2"); scope.Options.EnablePrivileges = true; WqlEventQuery query = new WqlEventQuery("Select * From __InstanceCreationEvent Within 1 Where TargetInstance ISA 'Win32_DiskDrive'"); watcher = new ManagementEventWatcher(scope, query); watcher.EventArrived += new EventArrivedEventHandler(watcher_EventArrived); watcher.Start(); Console.ReadLine(); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { if (watcher != null) watcher.Stop(); } } Everything seems to work and everything is fine, but there is one thing, but if you remove Console.ReadLine() after running the watcher , does the code stop working? How to deal with it?