好的,所以我的问题是我必须捕获删除和重命名事件(我可以这样做)。并修改线程中的数据以处理此问题,以便删除已删除的文件并更改重命名文件的数据。这是系统的伪代码,只是为了了解它的外观。每当我删除时,系统都会抛出一个异常,但它没有被捕获,所以我一直很难弄清楚如何解决或重写解决方案。另一部分是我将同时运行多个经理,但我想如果我不能让一个工作......那么这是徒劳的。
Main
{
public void Run()
{
List<FileInfo> someData = new List<FileInfo>();
FileWatcher fileWatcher = new FileWatcher(@"C:\USers\user1\Documents");
fileWatcher.NotifyFilter = NotifyFilter.Last
fileWatcher.Deleted += new FileSystemEventHandler(OnDelete);
fileWatcher.EnableRaisingEvents = true;
Manager aManager = new Manager(someData);
Thread aThread = new Thread(new ThreadStart(aManager.ExecuteTask));
aThread.Start();
}
static void OnDelete(object sender, Event e)
{
aManager.Pause();
aManager.RemoveData(e.FileInfo);
aManager.Resume();
}
}
Manager
{
ExecuteTask()
{
while(someData.Count > 0)
{
while (paused) ; // <- This is something I am trying to add
PreformSubTask(someData[0]);
}
}
PreformSubTask()
{
lock (_locker)
{
Worker someWorker = new Worker(someData[0]);
Thread someThread = new Thread(new ThreadStart(worker.ExecuteTask()));
}
worker.Join(someSetOfTime);
lock(_locker)
{
someData.RemoveAt(0);
}
}
Pause()
{
lock (_locker)
{
if (!paused) paused = true;
}
}
Resume
{
lock (_locker)
{
if (paused) paused = false;
}
}
RemoveData(FileInfo toRemove)
{
someData.RemoveAll(sd => sd.Equals(someData));
}
}