0

my .net service application started crash occasionally. Once investigate in windows event viewer, I get the below message:

Application: myapp.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.IO.IOException at System.IO.__Error.WinIOError(Int32, System.String) at System.IO.__Error.WinIOError() at System.Threading.EventWaitHandle.Set() at System.IO.FileStreamAsyncResult.AsyncFSCallback(UInt32, UInt32, System.Threading.NativeOverlapped*) at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32, UInt32, System.Threading.NativeOverlapped*)

From the error message, I'm not sure which part of my source code is giving me this error. Do you guys know what error is this?

And is it that because I didn't put a try/catch block on some of my code that's why it will have this error and crashes my app?

Coolguy
  • 2,225
  • 12
  • 54
  • 81
  • Please don't close my topic. I really don't know what the error means... Please help. – Coolguy Oct 05 '16 at 21:03
  • Post your code please. It basically just sounds like there's an error and you didn't handle it so it forced itself to close. – KSib Oct 05 '16 at 21:08
  • I only have vague information for you. Yes, an unhandled exception is due to an exception that is not caught and handled by you. As for your actual exception, the stack trace doesn't seem to point to any of your code, and I don't know how to fix that. An IO exception can be thrown for a lot of reasons. Your program is apparently attaching a `FileStream` to a file as indicated here `System.IO.FileStreamAsyncResult.AsyncFSCallback`, and for example, if another program or thread obtains a lock on that file then you will get an IO exception when your file stream goes to interact with it. – Quantic Oct 05 '16 at 21:09
  • KSib, I don't think can post the code.. my app have close to 50 .cs files and I'm not sure which one that is causing this error.. – Coolguy Oct 05 '16 at 21:14
  • Quantic, u mean I have problem writing a file because of user control issue? Actually I tried run my app as admin but the error still occurs – Coolguy Oct 05 '16 at 21:16
  • If you can find the highest level call to wrap in a try/catch then do so even if you only "catch () { PrintExceptionInfo(); throw; }`. As for PrintExceptionInfo, you need to view the InnerExceptions because maybe Event Viewer is only showing you the top exception and not the inner ones. I basically use [this method](http://stackoverflow.com/a/9314420/5095502) to print InnerExceptions. It *could* be permissions, but more likely 2 programs or threads want to write to the same file so each goes to lock it and write, but only one is allowed to at a time and the other one will get an IO exception. – Quantic Oct 05 '16 at 21:24
  • First, you could try to use the debugger. Just run it without setting a breakpoint, it should halt automatically on uncaught exceptions. If that is not possible, you can set up an Application wide exception handler for uncaught exceptions which (hopefully) writes the details e.g. into a file before the programm crashes. – CShark Oct 05 '16 at 22:09
  • CShark, my source code have more than 50 of .cs files. I'm not sure where the error is so not sure where to put the breakpoint even if i run debugger mode. – Coolguy Oct 06 '16 at 07:39

1 Answers1

0

This exception will be thrown when an I/O errors occurs. When process can't read or write correctly. Maybe Its because of your threading,It can't be done correctly.

"And is it that because I didn't put a try/catch block on some of my code that's why it will have this error and crashes my app?" -> And yes,you see the error because you didn't use any try/catch block.

Behdad
  • 1,459
  • 3
  • 24
  • 36
  • Is it because of user control issue? Actually I tried run my app as admin but the error still occurs – Coolguy Oct 05 '16 at 21:19
  • It does not belong to user control, because if it was, the exception was Access Violation exception. I think its something wrong with your Async method. – Behdad Oct 05 '16 at 21:29
  • what is async method? Is it like what Quantic says, there's two threads what to write to same file? – Coolguy Oct 05 '16 at 21:41
  • Asynchronous methods are the functions(Void) which are runs on another thread to be give the application responsibility. It will be used for parallel processes. What code are you using? and what are you doing? Are you writing the file? Or reading? – Behdad Oct 05 '16 at 21:49
  • My coding have hundreds of writing file and reading file functions. Don't really know which one that is causing this error. Anyway to identify it guys? – Coolguy Oct 06 '16 at 07:37
  • There are many ways to know which part of code makes problem. Use try/catch block for each functions. And in catch block,use messagebox or console.writeline to show the error and also use numbers to identify which part has a problem. And easier than this,you can use breakpoint in Visual Studio. – Behdad Oct 06 '16 at 08:00