private void Form1_Load(object sender, System.EventArgs e)
{
FileSystemWatcher p = new FileSystemWatcher("d:\\");
p.EnableRaisingEvents = true;
p.IncludeSubdirectories = true;
p.Changed+=new FileSystemEventHandler(p_Changed);
p.Created+=new FileSystemEventHandler(p_Created);
p.Deleted+=new FileSystemEventHandler(p_Deleted);
{
FileSystemWatcher p = new FileSystemWatcher("d:\\");
p.EnableRaisingEvents = true;
p.IncludeSubdirectories = true;
p.Changed+=new FileSystemEventHandler(p_Changed);
p.Created+=new FileSystemEventHandler(p_Created);
p.Deleted+=new FileSystemEventHandler(p_Deleted);
CheckForIllegalCrossThreadCalls = false; //线程的问题
}
private void p_Changed(object sender, FileSystemEventArgs e)
{
string s = e.Name;
this.listBox1.Items.Add(s+"文件被更改于 "+DateTime.Now);
}
private void p_Created(object sender, FileSystemEventArgs e)
{
string s = e.Name;
this.listBox1.Items.Add(s+"文件被创建于 "+DateTime.Now);
}
private void p_Deleted(object sender, FileSystemEventArgs e)
{
string s = e.Name;
this.listBox1.Items.Add(s+"文件被删除于 "+DateTime.Now);
}
}
private void p_Changed(object sender, FileSystemEventArgs e)
{
string s = e.Name;
this.listBox1.Items.Add(s+"文件被更改于 "+DateTime.Now);
}
private void p_Created(object sender, FileSystemEventArgs e)
{
string s = e.Name;
this.listBox1.Items.Add(s+"文件被创建于 "+DateTime.Now);
}
private void p_Deleted(object sender, FileSystemEventArgs e)
{
string s = e.Name;
this.listBox1.Items.Add(s+"文件被删除于 "+DateTime.Now);
}