1

ここで本当に厄介な問題が発生しました..次のコードを検討してください:

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() メソッドの単純なラッパーです。まあ、それはまったく機能しません。取り扱い方法を切り離しても(-= _KindlePlugedEventWatcher_EventArrived)... 2回目の発射を続けます。さらに、Dispose() を呼び出してみました。役に立たない: ミュウ オブジェクトはまだ生きている!!!

誰かがアイデアを持っていますか?

4

0 に答える 0