Espera.Core.RemovableDriveNotifier.StartRemoveWatcher C# (CSharp) Method

StartRemoveWatcher() private method

private StartRemoveWatcher ( ) : void
return void
        private void StartRemoveWatcher()
        {
            var scope = new ManagementScope("root\\CIMV2") { Options = { EnablePrivileges = true } };

            var query = new WqlEventQuery
            {
                EventClassName = "__InstanceDeletionEvent",
                WithinInterval = TimeSpan.FromSeconds(3),
                Condition = "TargetInstance ISA 'Win32_USBControllerdevice'"
            };

            this.removeWatcher = new ManagementEventWatcher(scope, query);
            this.removeWatcher.EventArrived += (sender, e) => this.DriveRemoved.RaiseSafe(this, EventArgs.Empty);

            this.removeWatcher.Start();
        }

Usage Example

        public static RemovableDriveNotifier Create()
        {
            var notifier = new RemovableDriveNotifier();
            notifier.StartInsertWatcher();
            notifier.StartRemoveWatcher();

            return notifier;
        }
All Usage Examples Of Espera.Core.RemovableDriveNotifier::StartRemoveWatcher