-2

i have a C# Application that changes a .txt File all the time while running. do you guys have any idea to control the .txt file and show a message when it has not changed since ( for example 1 Minute). So i can check if my application stops running.

thanks for any help or suggestion.

Aladin
  • 13
  • 2
  • What about using updatedTime stamp of the file? – G_S Mar 07 '19 at 09:50
  • 1
    Well it's generally a bad idea to monitor your application by checking whether it modified a txt file. But if you really want to do it like that you can check the LastModifiedDate on the FileInfo object. – Kristóf Tóth Mar 07 '19 at 09:50
  • [File.GetLastWriteTime](https://learn.microsoft.com/en-us/dotnet/api/system.io.file.getlastwritetime?redirectedfrom=MSDN&view=netframework-4.7.2#System_IO_File_GetLastWriteTime_System_String_) is what you need – styx Mar 07 '19 at 09:50
  • 1
    Also, file watcher is an option https://stackoverflow.com/questions/15017506/using-filesystemwatcher-to-monitor-a-directory – The scion Mar 07 '19 at 09:55

1 Answers1

0

Try this:

var lastWriteTime = File.GetLastWriteTime("someFilePath");

This returns the date and time the specified file or directory was last written to.