Vì một lý do nào đó, số FileSystemWatcher
của tôi không kích hoạt bất kỳ sự kiện nào. Tôi muốn biết bất cứ lúc nào một tập tin mới được tạo ra, xóa hoặc đổi tên trong thư mục của tôi. _myFolderPath
đang được đặt chính xác, tôi đã kiểm tra.FileSystemWatcher không kích hoạt sự kiện
Đây là mã hiện tại của tôi:
public void Setup() {
var fileSystemWatcher = new FileSystemWatcher(_myFolderPath);
fileSystemWatcher.NotifyFilter = NotifyFilters.LastAccess |
NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
fileSystemWatcher.Changed += FileSystemWatcherChanged;
fileSystemWatcher.Created += FileSystemWatcherChanged;
fileSystemWatcher.Deleted += FileSystemWatcherChanged;
fileSystemWatcher.Renamed += FileSystemWatcherChanged;
fileSystemWatcher.Filter = "*.*";
fileSystemWatcher.EnableRaisingEvents = true;
}
private void FileSystemWatcherChanged(object sender, FileSystemEventArgs e)
{
MessageBox.Show("Queue changed");
listBoxQueuedForms.Items.Clear();
foreach (var fileInfo in Directory.GetFiles(_myFolderPath, "*.*", SearchOption.TopDirectoryOnly))
{
listBoxQueuedForms.Items.Add(fileInfo));
}
}
bạn đã làm gì để xác minh rằng một tình huống xảy ra trong đó những sự kiện đó nên sa thải? – tnw
Tôi đã tạo, đổi tên và xóa các tệp theo cách thủ công trong thư mục của mình. Không có gì cháy. – gwin003
Ổ đĩa cục bộ, thư mục AppData/Roaming của nó cụ thể hơn – gwin003