[問題] 如何利用timer控制FileSystemWatcher的事件?
請教各位大大
目前使用FileSystemWatcher監聽資料夾
當資料夾內有文件建立或刪除
即顯示對話視窗(測試)
是否可以利用timer方式處理FileSystemWatcher的事件
例如:
每1分鐘內資料夾內是否有資料新增
有->A動作
無->B動作
就一分鐘檢查一次,不要一新增就動作
是否可以用timer和FileSystemWatcher實現?
還是有其他比較好的方法呢?
下面是我的程式碼
namespace Works
{
public partial class Form1 : Form
{
FileSystemWatcher Wc = new FileSystemWatcher();
public Form1()
{
InitializeComponent();
timer1.Interval = 1000 * 60;
}
private void timer1_Tick(object sender, EventArgs e)
{
MyFileSystemWatcher();
}
private void MyFileSystemWatcher()
{
Wc.Path = @"C:\";
Wc.Filter = "*.TXT";
Wc.IncludeSubdirectories = true;
Wc.EnableRaisingEvents = true;
Wc.Created += new FileSystemEventHandler(Wc_Created);
Wc.Deleted += new FileSystemEventHandler(Wc_Deleted);
}
private void Wc_Created(object sender, FileSystemEventArgs e)
{
MessageBox.Show("有檔案被新增");
}
private void Wc_Deleted(object sender, FileSystemEventArgs e)
{
MessageBox.Show("有檔案被刪除");
}
}
}
請各位大大指教....
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.121.25.20
→
02/15 22:56, , 1F
02/15 22:56, 1F
→
02/15 22:57, , 2F
02/15 22:57, 2F
→
02/15 23:18, , 3F
02/15 23:18, 3F
→
02/16 23:52, , 4F
02/16 23:52, 4F
→
02/16 23:53, , 5F
02/16 23:53, 5F
→
02/16 23:54, , 6F
02/16 23:54, 6F
→
02/17 10:48, , 7F
02/17 10:48, 7F