Linked Questions

Popular Questions

DriveInfo.IsReady Not Responding and Stuck

Asked by At

I'm checking removable devices with DriverInfo.isReady but whenever i plugged corrupted usb device it's block all threads and stuck.I tried with try catch but even try catch it's stucking again.I cant even get total space of device.Any codes related to usb device not working and windows ui hangs out.

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);
        }

Related Questions