Re: Converting an application to work on a network
- From: "Dave Sexton" <dave@jwa[remove.this]online.com>
- Date: Tue, 28 Nov 2006 16:13:47 -0500
Hi Adrian,
(1) I had a problem passing in the
file access parameter. I must have done something wrong. I made a small
change to your code that works fine.
You shouldn't have had to make any changes to my code, only your own. My
test code works fine, accepting a FileAccess parameter. But if you've
solved the problem, then great :)
2.) If a file is to be read, that does
not exist, the application will get into an endless loop. I am now
logging
if a file is approached for reading that doesn't exist, enabling easy
maintenance to take place. (The system is too big to test it through for
this possible bug cause. I was made aware of this bug because one
application seized up in this way.) I have done all the work now. But I
need
to write another application that will interact with the same files. Then
I
will give your original code another try, and I will get back to you if I
may.
FYI, you should always check File.Exists before attempting to open a file if
you aren't sure whether it will be available, or use
FileAccess.OpenOrCreate, as in the test code that I posted.
There is a bug in my original example since it uses FileAccess.Open (sorry).
I fixed it in the test code that I posted afterwards by changing it to
FileAccess.OpenOrCreate.
If you are going to use FileAccess.Open instead of FileAccess.OpenOrCreate,
you should catch FileNotFoundException as well (since it derives from
IOException it's being caught and swallowed in my original example, which is
the bug).
Here's a revised version of the try..catch block for both my test code and
original examples (fixing some other potential bugs as well):
try
{
stream = new FileStream(path, FileMode.Open, access);
}
catch (PathTooLongException)
{
throw;
}
catch (DirectoryNotFoundException)
{
throw;
}
catch (FileNotFoundException)
{
throw;
}
catch (IOException)
{
System.Threading.Thread.Sleep(500);
}
catch (UnauthorizedAccessException)
{
System.Threading.Thread.Sleep(500);
}
--
Dave Sexton
.
- Follow-Ups:
- Re: Converting an application to work on a network
- From: > Adrian <
- Re: Converting an application to work on a network
- References:
- Re: Converting an application to work on a network
- From: Dave Sexton
- Re: Converting an application to work on a network
- From: > Adrian <
- Re: Converting an application to work on a network
- From: Dave Sexton
- Re: Converting an application to work on a network
- From: > Adrian <
- Re: Converting an application to work on a network
- Prev by Date: Using C# class in javascript
- Next by Date: Re: Your opinion please
- Previous by thread: Re: Converting an application to work on a network
- Next by thread: Re: Converting an application to work on a network
- Index(es):
Relevant Pages
|