File listener - how can I know when the file is accessable?
I have a f开发者_如何学编程ile listener on a win service.
I raise event on file created/
some time I get execption "cannot access to the file because it being used by another program" do someone has an idea?
You could use FileSystemWatcher
to get notification on the file system but you should be more explicit if possible.
More info on it here: http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx
My suggestion, even when using a FileSystem watcher, is simply to do a Thread.Sleep(1000) after the FileCreated (or whichever event you are watching) has fired, so that you are 100% sure that the previous process has done with it. I have had a similar experience when using FileSystem watchers, and pausing for a while before trying the access the file fixed the issue.
精彩评论