- 积分
- 279
- 明经币
- 个
- 注册时间
- 2006-11-9
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
想做一个利用FileSystemWatcher监控某个文件夹下的dwg文件变化,然后对变化的文件进行处理的命令。
部分代码如下
[CommandMethod("ShowTheWatcher", CommandFlags.Transparent)]
public void ShowTheWatcher()
{
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = strPath;
watcher.Filter = "*.dwg";
watcher.Changed += new FileSystemEventHandler(OnProcess);
watcher.Created += new FileSystemEventHandler(OnProcess);
watcher.Deleted += new FileSystemEventHandler(OnProcess);
watcher.Renamed += new RenamedEventHandler(OnRenamed);
watcher.EnableRaisingEvents = true;
}
}
private void OnProcess(object source, FileSystemEventArgs e)
{
if (e.ChangeType == WatcherChangeTypes.Created)
{
OnCreated(source, e);
}
else if (e.ChangeType == WatcherChangeTypes.Changed)
{
OnChanged(source, e);
}
else if (e.ChangeType == WatcherChangeTypes.Deleted)
{
OnDeleted(source, e);
}
}
//测试时删除某个文件,可以进入到事件处理逻辑中,打开指定的文件时报错。
private void OnDeleted(object source, FileSystemEventArgs e)
{
try
{
Document dcOpeating = Application.DocumentManager.Open(@"E:\Workpath\@测试图纸集\津2分图.dwg", false);
Database dbOperating = dcOpeating.Database;
DocumentLock dlock = dcOpeating.LockDocument();
Transaction transOperating = dbOperating.TransactionManager.StartTransaction();
Editor edOperating = dcOpeating.Editor;
}
catch (System.Exception exx)
{
}
}
执行到Open行时会出现FATAL ERROR.
求助各位大神了,谢谢
|
|