i know this code dont work but is describes good what im trying to do, i want to run the code inside the if check when Lastwritetime is greater then oldvalue date.
private void timer1_Tick(object sender, EventArgs e)
{
DateTime lastWriteTime = File.GetLastWriteTime(@"C:\temp\test_folder\TestFile.txt");
if (lastWriteTime.ToString() > oldValue.ToString())
{
MessageBox.Show("Succsess");
}
string oldValue = lastWriteTime.ToString();
}
edit:
im not using SystemfileWatcher because of the mulitple events raised on change.
Why are you comparing string representations? If
oldValueisDateTimeas well, just compare them as is:Plus, make sure that the scope of
oldValueis greater than the scope oftimer1_Tick(that is, ensure that it’s a class member variable).And of course, do not reinvent the wheel:
FileSystemWatcher.