C# - Predict file system events on folder delete

前端 未结 3 527
礼貌的吻别
礼貌的吻别 2021-01-18 17:37

This is more a question about what\'s the best practice in implementing this.

I have a FileSystemWatcher which should inform me about User\'s changes on

3条回答
  •  醉梦人生
    2021-01-18 18:04

    Ok here is my solution of the problem:

    Just for delete command:

    I implemented 2 lists, one for file deletes and one for folder deletes.

    file list entrys have no timeout. If I delete a file I create a list entry and if I get the expected delete event I remove the entry as before.

    folder list entrys have no timeout after create. I can command them manually to time out after a second by a special method. If I delete a folder I add a deleteFolder list entry. Every delete event from this folder or file or subfolder or subfolderfile is ignored because of this delete folder entry. After the delete is finished I arm the timeout for the deleteFolder entry. If the delete throws an exception I do the same. So I expect to get all events after a second. So I'm ignoring all events if the delete command works or not. After this the deleteFolder list entry gets deleted.

    Limitations: 1. all delete events have to come in one second after the delete happened. 2. it is not allowed to delete a folder like this:
    delete folder (completed)
    create folder again
    wait less then 1 second
    delete folder again (timeout has not finished of the delete folder list entry)

    Hope this helps somebody even it is very complicated ^^

提交回复
热议问题