c# - Is filesystemwatcher the right way to monitor a file? -


I know that this is a common question, but I'm just opening it for discussion, I believe it That someone else should have done this and I want to code a lot to know about my solution.

Here I have a user who will add one file to the database as an OLE object and some attributes will be added to the file - it is connected to the project, version etc. Using Access I ???? Customer is not mine!

When they want to edit it, they have to check it at this level, I want to monitor the file and when I save it, to get it back to the database.

I am thinking that file system watcher is my best way - monitor changes and save it back when changes also start and I can get access to the file, if the database If it is still opened, it will be locked, so I know that the user is not finished.

So my question in short is that file system watchdog is properly from this perspective? Anyone have any more suggestions?

Thanks, Jim

As M4 is called GNV5, FileSystemWatcher will work for this, but using a code is a bit overkill because it is quite error prone and requires very accurate usage patterns to succeed, it also has certain overhead This is because it should hook into a file system driver in kernel mode.

An alternative solution can use a poll.

  FileInfo info = new FileInfo (file path); Date time old time = info.LastWriteTimeUtc; While (true) wait (1000); info.Refresh ();} while (info.LastWriteTimeUtc == old time); try {use (stream s = File.OpenRead (filePath)) // OK, file is modified and unlocked copy back} break;} hold (IOException) {// file is locked, try again oldTime = info.LastWriteTimeUtc;}}   

this Waiting for the first time to change the file, and then checks to unlock it.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -