DriveInfo.IsReady没有响应和卡住

时间:2019-02-07 13:49:13

标签: windows visual-studio

我正在使用DriverInfo.isReady检查可移动设备,但是每当插入损坏的USB设备时,它都会阻塞所有线程并卡住。我尝试使用try catch,但甚至尝试将其再次卡住。我什至无法获得设备的总空间。与USB设备相关的代码无法正常工作,Windows ui会挂出。

DriveInfo[] allDrives = DriveInfo.GetDrives();

    foreach (DriveInfo d in allDrives)
    {
        Console.WriteLine("Drive {0}", d.Name);
        Console.WriteLine("  Drive type: {0}", d.DriveType);
        if (d.IsReady == true) # stuck here
        {
            Console.WriteLine("  Volume label: {0}", d.VolumeLabel);
            Console.WriteLine("  File system: {0}", d.DriveFormat);
            Console.WriteLine(
                "  Available space to current user:{0, 15} bytes", 
                d.AvailableFreeSpace);

            Console.WriteLine(
                "  Total available space:          {0, 15} bytes",
                d.TotalFreeSpace);

            Console.WriteLine(
                "  Total size of drive:            {0, 15} bytes ",
                d.TotalSize);
        }

0 个答案:

没有答案