0

I'm trying to open a file from a USB-Drive in my c# application. I handle the IOException in C# If the file is corrupted. Unfortunately also Windows 10 is showing a message box which I want to suppress.

try
{
  // Open file and read all lines to trigger the exception if file is bad
  string[] lines = File.ReadAllLines(s);
}
catch (IOException e)
{
  // Corrupted File found Execute CHKDSK on that drive
}

C# is handling the exception as expected. But Windows is showing the following message:

enter image description here

Is there a way to suppress the Windows warning window? Thanks for your help.

Chris
  • 23
  • 3
  • 1
    Maybe run the CheckDisk utility? –  Sep 10 '19 at 07:21
  • What is the exception type when that message is shown? – mjwills Sep 10 '19 at 07:22
  • The exeption I catch in C# has the following stack trace: "at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)\r\n at System.IO.FileStream.ReadCore(Byte[] buffer, Int32 offset, Int32 count)\r\n at System.IO.FileStream.Read(Byte[] array, Int32 offset, Int32 count)\r\n at System.IO.Stream... – Chris Sep 10 '19 at 07:49
  • 1
    The Windows warning is not coming out of my C# Application - it is opened by Windows it self. – Chris Sep 10 '19 at 08:03

1 Answers1

0

One solution is to find the Windows message window by title and close it this way: How to close the window by its name?

It is working but it is a hack. Any other solutions are highly welcome.

Chris
  • 23
  • 3
  • Suppressing this critical error is quite unwise, especially so for USB memory sticks. https://www.theregister.co.uk/2016/04/11/half_plug_in_found_drives/ – Hans Passant Sep 10 '19 at 13:01