11 个解决方案
#1
帮你顶!!!!同问!!!
#2
http://msdn.microsoft.com/zh-cn/library/vstudio/system.io.filesystemwatcher.aspx
#3
filesystemwatcher这个类可以在达到效果,具体你可参考
http://msdn.microsoft.com/zh-cn/library/vstudio/system.io.filesystemwatcher.aspx
http://msdn.microsoft.com/zh-cn/library/vstudio/system.io.filesystemwatcher.aspx
#4
FileSystemWatcher 用这个
#5
前段时间写过
#6
#7
FileSystemWatcher
#8
可以用多线程实时同步获取..
#9
FileSystemWatcher
#10
// Create a new FileSystemWatcher and set its properties.
FileSystemWatcher watcher = new FileSystemWatcher();
/// <summary>
/// 监听文件夹
/// </summary>
public void ThreadDirectory()
{
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(path); System.IO.DirectoryInfo[] dirs = dir.GetDirectories();
if (dirs.Length > 0)
{
//直接走
Send();
}
else
{
watcher.Path = path;
watcher.IncludeSubdirectories = true;
//监听类型
watcher.NotifyFilter = NotifyFilters.FileName;
//监听该文件夹中的所有文件
watcher.Filter = "*.*";
// 执行操作 当文件创建的时候触发事件
watcher.Created += new FileSystemEventHandler(watcher_Created);
// 启用监听
watcher.EnableRaisingEvents = true;
}
}
void watcher_Created(object sender, FileSystemEventArgs e)
{
Send();
}
调用:
Thread t1 = new Thread(ThreadDirectory);
t1.Start();//线程开启
FileSystemWatcher watcher = new FileSystemWatcher();
/// <summary>
/// 监听文件夹
/// </summary>
public void ThreadDirectory()
{
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(path); System.IO.DirectoryInfo[] dirs = dir.GetDirectories();
if (dirs.Length > 0)
{
//直接走
Send();
}
else
{
watcher.Path = path;
watcher.IncludeSubdirectories = true;
//监听类型
watcher.NotifyFilter = NotifyFilters.FileName;
//监听该文件夹中的所有文件
watcher.Filter = "*.*";
// 执行操作 当文件创建的时候触发事件
watcher.Created += new FileSystemEventHandler(watcher_Created);
// 启用监听
watcher.EnableRaisingEvents = true;
}
}
void watcher_Created(object sender, FileSystemEventArgs e)
{
Send();
}
调用:
Thread t1 = new Thread(ThreadDirectory);
t1.Start();//线程开启
#11
if (dirs.Length > 0)
{
//直接走
Send();
}
我的是 判断如果文件夹里有文件就直接读取,没有的话等待文件创建然后触发事件走else
{
//直接走
Send();
}
我的是 判断如果文件夹里有文件就直接读取,没有的话等待文件创建然后触发事件走else
#1
帮你顶!!!!同问!!!
#2
http://msdn.microsoft.com/zh-cn/library/vstudio/system.io.filesystemwatcher.aspx
#3
filesystemwatcher这个类可以在达到效果,具体你可参考
http://msdn.microsoft.com/zh-cn/library/vstudio/system.io.filesystemwatcher.aspx
http://msdn.microsoft.com/zh-cn/library/vstudio/system.io.filesystemwatcher.aspx
#4
FileSystemWatcher 用这个
#5
前段时间写过
#6
#7
FileSystemWatcher
#8
可以用多线程实时同步获取..
#9
FileSystemWatcher
#10
// Create a new FileSystemWatcher and set its properties.
FileSystemWatcher watcher = new FileSystemWatcher();
/// <summary>
/// 监听文件夹
/// </summary>
public void ThreadDirectory()
{
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(path); System.IO.DirectoryInfo[] dirs = dir.GetDirectories();
if (dirs.Length > 0)
{
//直接走
Send();
}
else
{
watcher.Path = path;
watcher.IncludeSubdirectories = true;
//监听类型
watcher.NotifyFilter = NotifyFilters.FileName;
//监听该文件夹中的所有文件
watcher.Filter = "*.*";
// 执行操作 当文件创建的时候触发事件
watcher.Created += new FileSystemEventHandler(watcher_Created);
// 启用监听
watcher.EnableRaisingEvents = true;
}
}
void watcher_Created(object sender, FileSystemEventArgs e)
{
Send();
}
调用:
Thread t1 = new Thread(ThreadDirectory);
t1.Start();//线程开启
FileSystemWatcher watcher = new FileSystemWatcher();
/// <summary>
/// 监听文件夹
/// </summary>
public void ThreadDirectory()
{
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(path); System.IO.DirectoryInfo[] dirs = dir.GetDirectories();
if (dirs.Length > 0)
{
//直接走
Send();
}
else
{
watcher.Path = path;
watcher.IncludeSubdirectories = true;
//监听类型
watcher.NotifyFilter = NotifyFilters.FileName;
//监听该文件夹中的所有文件
watcher.Filter = "*.*";
// 执行操作 当文件创建的时候触发事件
watcher.Created += new FileSystemEventHandler(watcher_Created);
// 启用监听
watcher.EnableRaisingEvents = true;
}
}
void watcher_Created(object sender, FileSystemEventArgs e)
{
Send();
}
调用:
Thread t1 = new Thread(ThreadDirectory);
t1.Start();//线程开启
#11
if (dirs.Length > 0)
{
//直接走
Send();
}
我的是 判断如果文件夹里有文件就直接读取,没有的话等待文件创建然后触发事件走else
{
//直接走
Send();
}
我的是 判断如果文件夹里有文件就直接读取,没有的话等待文件创建然后触发事件走else