2
Reply

System.IO Error - please help

Tiger

Tiger

Feb 19 2010 6:38 AM
2.7k

Hi,
I am trying to write a console application which is watching a particular directory and if a file comes, it works upon it.
It works fine when I execute this in debug mode with lots of file dropped into that directory.
But when I execute it in the run mode it only works for the first file that is dropped in the directory. It does detect that files are coming in but it cannot do anything with them. It throws the following error:
--------------------------------------------------  Error ---------------------------------------------------------------------------------------------
Exception is:    at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights
, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolea
n bFromProxy)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferS
ize, FileOptions options)
   at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, I
nt32 bufferSize)
   at System.IO.StreamReader..ctor(String path)
----------------------------------------------------------------------------------------------------------------------------
Stack trace shows that it failing (for second file onwards) at the following line of code:
StreamReader reader =
new StreamReader(myfilename);
Note that I am doing this in try catch finally block and also calling reader.dispose() in the finally block.
Your help will be much appriciated. Have looked over the internet but have not found a solution.
Regards,

Answers (2)