大家好,
//请我有一个简单的问题。我需要,当 Filesystemwatcher 看到 File -after fsw 启动关闭应用程序的计时器(应用程序将在 2 秒后关闭,文件创建时间)//
感谢用户“永不放弃” *
最后我有这个“简单”的代码:-)
public partial class Form1 : Form
{
System.Timers.Timer casovac = new System.Timers.Timer();
int totalSeconds = 0;
public Form1()
{
InitializeComponent();
casovac.Interval = 1000;
casovac.Elapsed += new System.Timers.ElapsedEventHandler(cas_elapsed);
}
void cas_elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
totalSeconds++;
if (totalSeconds == 3)
{
casovac.Stop();
Application.Exit();
}
}
private void Form1_Load(object sender, EventArgs e)
{
FileSystemWatcher fsw = new FileSystemWatcher();
fsw.Path = Application.StartupPath + "\\OUT\\";
fsw.Filter = "file.exe";
fsw.IncludeSubdirectories = true;
fsw.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
fsw.Changed += new FileSystemEventHandler(fsw_changed);
fsw.Created += new FileSystemEventHandler(fsw_changed);
fsw.EnableRaisingEvents = true;
}
private void fsw_changed(object source, FileSystemEventArgs e)
{
casovac.Start();
}
}
}
但是谢谢大家;-)