using System;
using System.IO;
using System.Xml;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Diagnostics;
using SynchroManager;
using SynchroManager.baseclass;
namespace SynchroManager
{
public partial class frmChange : Form
{
public frmChange()
{
InitializeComponent();
}
delegate void SetTextCallback(string text);
private string s;
private string _dowlist;
private string _LookFolder;
private Thread demoThread = null;
private void btnRun_Click(object sender, EventArgs e)
{
FileSystemWatcher watcher = new FileSystemWatcher();
if (txtFilter.Text.Length < 2)
{
MessageBox.Show("请选择监视目录");
return;
}
watcher.Path = txtFilter.Text;
watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
watcher.Filter = "";
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.Created += new FileSystemEventHandler(OnCreated);
watcher.Deleted += new FileSystemEventHandler(OnDeleted);
watcher.Renamed += new RenamedEventHandler(OnRenamed);
watcher.EnableRaisingEvents = true;
watcher.EndInit();
}
private void OnChanged(object source, FileSystemEventArgs e)
{
s = e.FullPath + " " + e.ChangeType;
this.demoThread = new Thread(new ThreadStart(this.ThreadProcSafe));
this.demoThread.Start();
//StreamWriter strW = File.CreateText("C:Inetpub tprootdownlist.txt");
//strW.WriteLine(s);
//strW.Close();
}
private void OnCreated(object source, FileSystemEventArgs e)
{
s = e.FullPath + " " + e.ChangeType;
this.demoThread = new Thread(new ThreadStart(this.ThreadProcSafe));
this.demoThread.Start();
//StreamWriter strW = File.CreateText("C:Inetpub tprootdownlist.txt");
//strW.WriteLine(s);
//strW.Close();
}
private void OnDeleted(object source, FileSystemEventArgs e)
{
s = e.FullPath + " " + e.ChangeType;
this.demoThread = new Thread(new ThreadStart(this.ThreadProcSafe));
this.demoThread.Start();
//StreamWriter strW = File.CreateText("C:Inetpub tprootdownlist.txt");
//strW.WriteLine(s);
//strW.Close();
}
private void OnRenamed(object source, FileSystemEventArgs e)
{
s = e.FullPath + " " + e.ChangeType;
this.demoThread = new Thread(new ThreadStart(this.ThreadProcSafe));
this.demoThread.Start();
//StreamWriter strW = File.CreateText("C:Inetpub tprootdownlist.txt");
//while((st=strR.ReadLine())!=null;
//strW.WriteLine(s);
//strW.Close();
}
private void SetText(string text)
{
if (this.lblist.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText);
this.Invoke(d, new object[] { text });
}
else
{
this.lblist.Items.Add(text);
}
}
private void ThreadProcSafe()
{
this.SetText(s);
}
}
}
}
using System.IO;
using System.Xml;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Diagnostics;
using SynchroManager;
using SynchroManager.baseclass;
namespace SynchroManager
{
public partial class frmChange : Form
{
public frmChange()
{
InitializeComponent();
}
delegate void SetTextCallback(string text);
private string s;
private string _dowlist;
private string _LookFolder;
private Thread demoThread = null;
private void btnRun_Click(object sender, EventArgs e)
{
FileSystemWatcher watcher = new FileSystemWatcher();
if (txtFilter.Text.Length < 2)
{
MessageBox.Show("请选择监视目录");
return;
}
watcher.Path = txtFilter.Text;
watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
watcher.Filter = "";
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.Created += new FileSystemEventHandler(OnCreated);
watcher.Deleted += new FileSystemEventHandler(OnDeleted);
watcher.Renamed += new RenamedEventHandler(OnRenamed);
watcher.EnableRaisingEvents = true;
watcher.EndInit();
}
private void OnChanged(object source, FileSystemEventArgs e)
{
s = e.FullPath + " " + e.ChangeType;
this.demoThread = new Thread(new ThreadStart(this.ThreadProcSafe));
this.demoThread.Start();
//StreamWriter strW = File.CreateText("C:Inetpub tprootdownlist.txt");
//strW.WriteLine(s);
//strW.Close();
}
private void OnCreated(object source, FileSystemEventArgs e)
{
s = e.FullPath + " " + e.ChangeType;
this.demoThread = new Thread(new ThreadStart(this.ThreadProcSafe));
this.demoThread.Start();
//StreamWriter strW = File.CreateText("C:Inetpub tprootdownlist.txt");
//strW.WriteLine(s);
//strW.Close();
}
private void OnDeleted(object source, FileSystemEventArgs e)
{
s = e.FullPath + " " + e.ChangeType;
this.demoThread = new Thread(new ThreadStart(this.ThreadProcSafe));
this.demoThread.Start();
//StreamWriter strW = File.CreateText("C:Inetpub tprootdownlist.txt");
//strW.WriteLine(s);
//strW.Close();
}
private void OnRenamed(object source, FileSystemEventArgs e)
{
s = e.FullPath + " " + e.ChangeType;
this.demoThread = new Thread(new ThreadStart(this.ThreadProcSafe));
this.demoThread.Start();
//StreamWriter strW = File.CreateText("C:Inetpub tprootdownlist.txt");
//while((st=strR.ReadLine())!=null;
//strW.WriteLine(s);
//strW.Close();
}
private void SetText(string text)
{
if (this.lblist.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText);
this.Invoke(d, new object[] { text });
}
else
{
this.lblist.Items.Add(text);
}
}
private void ThreadProcSafe()
{
this.SetText(s);
}
}
}
}