Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ManagementEventWatcher停止/启动/处理问题_C#_Wmi_Managementeventwatcher - Fatal编程技术网

C# ManagementEventWatcher停止/启动/处理问题

C# ManagementEventWatcher停止/启动/处理问题,c#,wmi,managementeventwatcher,C#,Wmi,Managementeventwatcher,我这里有一个很烦人的问题。。考虑下面的代码: private static void _KindlePlugedEventWatcher_EventArrived( object sender, EventArrivedEventArgs e) { var plugedLogicalDisk = (ManagementBaseObject)e.NewEvent["TargetInstance"]; if ((plugedLo

我这里有一个很烦人的问题。。考虑下面的代码:

private static void _KindlePlugedEventWatcher_EventArrived(
        object sender,
        EventArrivedEventArgs e)
    {
        var plugedLogicalDisk = (ManagementBaseObject)e.NewEvent["TargetInstance"];
        if ((plugedLogicalDisk["VolumeName"] as string) == _KindleName)
        {

            var kindleID = plugedLogicalDisk["DeviceID"] as string; // logical letter, like "F:"
            if (kindleID.IsNotNull() &&

                /* somewhy this event fires two times in a sequence,
                thus it is necessary to check,
                if such kindleID is already present 
                in the list of pluged devices;

                because of async sequence Pause() and Resume() 
                are necessary...*/
                !(PlugedDevices.HasItem(
                    (kindleDevice) => { return kindleDevice.ID == kindleID ? true : false; }
                )))

            {
                PauseListening();
                App.Current.Dispatcher.Invoke(
                    async () =>
                    {
                        try
                        {
                            var kindleDevice = await KindleDevice.Create(kindleID);
                            PlugedDevices.Add(kindleDevice);
                        }

                        catch (FileNotFoundException)
                        {
                            /* means that Kindle might not has 
                            'My Clippings.txt' at all,
                            or some IO melfunction happened */

                            throw;
                        }


                    });
                ResumeListening();
            }
        }
    }
Pause…()
Resume…()
都是MEW类提供的Stop()/Start()方法的简单包装。嗯,那根本不起作用。即使我使用分离处理方法(
-=\u KindlePlugedEventWatcher\u eventwatcher
)。。。它继续第二次开火。此外,我还尝试调用Dispose()。这没用:新的物体还活着

有人有主意吗