Home > database >  The best approach to check if file has been modified in c#
The best approach to check if file has been modified in c#

Time:10-31

So I have an app I am required to store the user login info locally using a text file , is windows file system watcher a good approach .The data inside the text files are well encrypted, and I tried to check the files using windows archive but everyone were saying it's not reliable. What's the best approach for my case? thanks alot

I must detect the smallest change in the directory but using the archive or by using time only they were not doing the job for me!

CodePudding user response:

Using the file system watcher is a good choice in most simple scenarios. But it sometimes has problems especially with network drives, long running watching, high change rates or watching hundreds of files simultanously.

In these cases watch the file yourself in the needed rate (100ms or slower) by using an endless running Task. In the first pace check size and last change time stamp with your last observation.

If this isn't enough, calculate a checksum from the file and compare these, but be aware, this means reading the whole file, which can make other problems depending on file size, I/O performance and change rate.

For the checksum itself take a simple good algorithm like SHA256.

  • Related