Koray Samsun

Hi i have an application that i listen file system with file system watcher and then i am able to move any file to another folder. When i use File.Copy method it always works fine but sometimes(not everytime) after that i can not open file with the code below

FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read);

fs.Close();

it gives error just as "File already in use", and this situation continues forever(till i close application). But if i try to open the file manually from its new folder, its okey i open it. Where am i wrong and why does it sometimes work and sometimes not Anyone any idea



Re: Visual C# General File.Move works but can't open the file

shimshon

if you used file.move before using the open method, you must close the filestream first.




Re: Visual C# General File.Move works but can't open the file

Koray Samsun

Thanks a lot ! that's definitely points to my mistake, i must be careful while using threads to check access to file