We have a .net server application (framework 1.1) that provides file
system interface to clients. The server application is running as a
windows service. Client communicates with the server through .net
remoting. When the server checks file existance, sometimes (once every
few files, sometimes 3-4, sometimes 10, not consistant), it
(File.Exists) could take up to 20 seconds to return, when the path is
a UNC path. It is immediate if we switch to use local path (however we
cannot do this for long term). Under the same context, a call to open
the file using FileStream is almost immediate as well with a UNC
path.

Does anyone has any insights why the File.Exists takes so long? Any
suggestions for workaround?

P.S.: loading all file names into memory is not an option as we only
serve one file at a time per client. The only other option I had is
NOT checking existance and catch exception in reading. The issue is
occuring at a customer site. They have been running fine for a long
time but recently experienced this performance issue. So this might
well be environmental but we couldn't figure out the cause.

Below is a block of the code in question:

public byte[] GetImage(string imageFileName, long imageOffset, int
imageLength, out bool found)
{
found = false;

try
{
if(!File.Exists(imageFileName))
return null;
byte[] buf = new byte[imageLength];

using( FileStream imageFile = new FileStream(imageFileName,
FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
imageFile.Seek(imageOffset, SeekOrigin.Begin);
int bytes = imageFile.Read(buf, 0, imageLength);
imageFile.Close();
}

found = true;
return buf;
}
catch (Exception ex)
{
throw new TwsRemotingException(ex.Message);
}
}

Thanks for any help.

Yanli