public MainControl() { InitializeComponent(); //初始化浏览器 this.initChartBrowser(); this.chartBrowser.Navigate(dirRoot + @"\Views\Browser\main.html"); //若过了试用期并且未注册,则不进行U盘监听 if (!deviceService.CheckEffective()) { return; } deviceDic = new Dictionary <string, bool>(); deviceNotifier = DeviceNotifier.OpenDeviceNotifier(); deviceNotifier.OnDeviceNotify += OnDeviceNotifyEvent; try { allUsbDrives = DriveInfo.GetDrives().Where(x => x.DriveType == DriveType.Removable).ToArray(); //开启任务异步操作,避免多个采集站统计加载时界面假死 Thread ts = new Thread(() => { var resourceIndex = 0; var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_LogicalDiskToPartition"); foreach (ManagementObject dm in searcher.Get()) { var drive = getValueInQuotes(dm["Dependent"].ToString()) + @"\"; diskArray = getValueInQuotes(dm["Antecedent"].ToString()).Split(','); driveNumber = Convert.ToInt32(diskArray[0].Remove(0, 6).Trim()); var disks = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive"); foreach (ManagementObject disk in disks.Get()) { if (disk["Name"].ToString() == ("\\\\.\\PHYSICALDRIVE" + driveNumber.ToString()) & disk["InterfaceType"].ToString() == "USB") { DeviceControl device = new DeviceControl(); var serialNumber = parseSerialFromDeviceID(disk["PNPDeviceID"].ToString()).ToUpper(); DriveInfo d = allUsbDrives.FirstOrDefault(x => x.Name == drive); if (d == null) { continue; } var deviceName = d.Name; var deviceRoot = d.RootDirectory; var checkToken = device.CheckDeviceToken(deviceName, serialNumber); if (checkToken < 0) { continue; } if (resourceIndex == 0) { MessageUtil.ShowMessage("资源已就绪,开始采集...", EnumData.MessageType.Information, this); resourceIndex++; } device.SetProgressDelegate += HandleRefreshProgess; Action <DirectoryInfo, string> copyAction = device.CopyFilesTo; copyAction.BeginInvoke(deviceRoot, serialNumber, null, null); } } } }); ts.IsBackground = true; ts.Start(); } catch { MessageUtil.ShowMessage("资源识别失败,请重启程序!", EnumData.MessageType.Warning, this); } }