Beispiel #1
0
        /// <summary>
        /// 监控任务
        /// </summary>
        public void WatcherTask()
        {
            USBDictionary.Get();
            Task.Factory.StartNew(() =>
            {
                Refresh();//第一次运行初始化USB列表
                while (!Token.IsCancellationRequested)
                {
                    if (HasEvent)
                    {
                        try
                        {
                            Refresh();

                            //USB设备发生改变触发事件
                            if (Ls.Ok(InsertDevice) || Ls.Ok(RemoveDevice))
                            {
                                USBChangeEvent?.Invoke(AllDevice, InsertDevice, RemoveDevice);
                                __ChangeTime = DateTime.Now;
                            }

                            //对插入事件做处理
                            if (ListTool.HasElements(InsertDevice))
                            {
                                USBInsertEvent?.Invoke(AllDevice, InsertDevice);
                                __InsertTime = DateTime.Now;
                            }

                            //对移除设备事件做处理
                            if (ListTool.HasElements(RemoveDevice))
                            {
                                USBRemoveEvent?.Invoke(AllDevice, RemoveDevice);
                                __RemoveTime = DateTime.Now;
                            }
                        }
                        catch { }
                        HasEvent = false;
                    }
                    Sleep.S(1);
                }
            });
        }
Beispiel #2
0
        private void ListenerTask()
        {
            Task.Factory.StartNew(() =>
            {
                while (!Token.IsCancellationRequested)
                {
                    try
                    {
                        Refresh();

                        //USB设备发生改变触发事件
                        if (Ls.Ok(InsertDevice) || Ls.Ok(RemoveDevice))
                        {
                            USBChangeEvent?.Invoke(AllDevice, InsertDevice, RemoveDevice);
                            __ChangeTime = DateTime.Now;
                        }

                        //对插入事件做处理
                        if (ListTool.HasElements(InsertDevice))
                        {
                            USBInsertEvent?.Invoke(AllDevice, InsertDevice);
                            __InsertTime = DateTime.Now;
                        }

                        //对移除设备事件做处理
                        if (ListTool.HasElements(RemoveDevice))
                        {
                            USBRemoveEvent?.Invoke(AllDevice, RemoveDevice);
                            __RemoveTime = DateTime.Now;
                        }
                    }
                    catch { }
                    Sleep.S(1);
                }
            });
        }