无论如何,我可以观看用于事件更改的Filesystem观察器对象过滤器(watcher.NotifyFilter)
IF (watcher.NotifyFilter ==true )
( call this method )
else
()
我想让IF / Else块24小时运行或将其作为服务安排
DateTime lastModified = System.IO.File.GetLastAccessTime("C:\\testfile.csv");
string Today_var = DateTime.Now.ToString("dd/MM/yyyy");
using (StreamWriter sw = new StreamWriter("C:\\Cscript_Activitylog.txt"))
{
sw.Write( DateTime.Now.ToLocalTime()+"\n\n");
sw.Write("----------------------- Activity Feed begins - Test file change ---------------------------");
sw.Write(lastModified.ToString("dd/MM/yyyy HH:mm"+"\n"));
sw.Write(DateTime.Now.ToString("dd/MM/yyyy HH:mm"+"\n"));
Console.Write( DateTime.Now.ToLocalTime()+"\n\n");
Console.Write("----------------------- Activity Feed begins - Test file change ---------------------------");
Console.Write(lastModified.ToString("dd/MM/yyyy HH:mm"+"\n"));
Console.Write(DateTime.Now.ToString("dd/MM/yyyy HH:mm"+"\n"));
//if file was modified today manual script to check every 30 min
// I intend to run this as service to check this but I have not managed yet to run this
code on console yet to convert to a service script
if(Today_var==lastModified.ToString("dd/MM/yyyy"))
{
Console.WriteLine("------- -------------------##----There is a file update today ----");
// set the time (In min in this case)
System.Timers.Timer t = new System.Timers.Timer(TimeSpan.FromMinutes(30).TotalMilliseconds);
t.Elapsed += new System.Timers.ElapsedEventHandler(your_method);
t.AutoReset = true;
t.Enabled = true;
}
//Struggling with this part
// How to do I check if filesystem watcher triggered any changes in the directory then
else if(fsw.Equals(true))
{
Process.Start("C:\\Do_this_file_Sync.bat");
Console.WriteLine("File system watcher notifier event found");
Thread.Sleep(3000);
}
else
{
Console.WriteLine("SLeeping 30000 - No file update today !");
}
Console.WriteLine("Finished Today {0}",DateTime.Now.ToLocalTime());
sw.Close();
}
我将非常感谢能够为控制台应用程序完成此代码的任何帮助。