public void AddFilePath(string path) { TreeNodeCollection nodes = treeView1.Nodes; foreach (var i in path.Split(new char[] { Path.DirectorySeparatorChar })) { if (!nodes.ContainsKey(i)) { TreeNode node = nodes.Add(i, i); node.ImageKey = GetImageKey(GetPathByNode(node)); node.SelectedImageKey = node.ImageKey; } nodes = nodes[i].Nodes; } string dir = Path.GetDirectoryName(path); if (!m_fileSysWatchers.ContainsKey(dir)) { FileSystemWatcher watcher = new FileSystemWatcher(dir); watcher.EnableRaisingEvents = true; watcher.IncludeSubdirectories = false; watcher.Changed += (o, e) => { DelegateQueue.PostDelegate(() => { if (this.FileChanged != null) { this.FileChanged(e.FullPath); } }); }; watcher.Deleted += (o, e) => { DelegateQueue.PostDelegate(() => { if (this.FileDeleted != null) { this.FileDeleted(e.FullPath); } }); }; m_fileSysWatchers.Add(dir, watcher); } }
static void Main() { Application.Idle += (o, e) => { DelegateQueue.InvokeDelegates(); }; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); }