Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys

I have a strange issue that I'm struggling to solve.

I have a FileStream (used to be just a SteamReader) that opens a file on the network.

It works fine on my machine and the test machine (both x64 windows 7 pro) and opens the file instantly.

However, when on it's server (x64 windows server 2008 R2) it gets to the point of trying to open the file, and sits there doing nothing. No exceptions, it just hangs.

The file opening is triggered by a FileSystemMonitor event, AND I use FileInfo to check the file is there, so there should be no issue in visibility.

The files are very rarely bigger than 20KB.

To add to the confusion, the server is in the data center, on the same switch as the machine it is getting the files from. When it works from my machine, it's going over a VPN connection...

Does anybody have any ideas that may shed some light on why my server won't open these files?
Posted
Comments
fjdiewornncalwe 21-Aug-13 11:00am    
Could it be an issue of permissions? In your local and test environments you are probably running under you credentials so you are able to open the file. FileInfo will still see the file and give you information on the file even if you don't have permission to open the file. I would think you would get an exception then rather than hanging, so I'm just adding this as a comment rather than a solution.
Paul Unsy 21-Aug-13 11:04am    
This was my original thought, so I transferred the offending code into a console app and ran it using my credentials. I have admin rights across the board, so this "seems" unlikely to be my issue. :(
ZurdoDev 21-Aug-13 11:02am    
Perhaps latency between machines. Does it eventually time out or open?
Bernhard Hiller 22-Aug-13 2:32am    
Opening files over a network is not good practise - it may slow down your apllication terribly.
Better copy the file to your local temp folder, open it there, and - if necessary - copy the changed file back to the network share.
An example from a previous project: an ini file containing the settings for all users was read via the network, using the Windows API to get all the entries. It worked quickly with our test cases, but some customers had many users, and with some 50 users customers used to complain. After changing to a local copy, things went smoothly also there.

Ok... Thanks for your comments guys, however it has started working now... Not made any changes, and I have no idea what was causing it.

It looks like I'm going to have to do some environmental diagnostics as this is supposed to be running as a service, and I don't want to lose stuff because of this issue...

Any suggestions are welcome, and I will post my findings (provided I have findings) in case anyone else may have similar issues.

Thanks
 
Share this answer
 
If the file is in a network folder, and the network connection to that folder breaks, FileStream open may freeze. The only solution is to put it in a new thread and kill that thread after a timeout, if needed.
 
Share this answer
 
Comments
Richard MacCutchan 8-Dec-15 4:24am    
This question is over two years old! Please do not add replies to out of date questions.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900