In some scenario, I need to call FileWatcher onDelete function in my application.
The below code works as expected. Please let let me know if there any better way to do this.
string path = @"C:\File\Test";
string part1, part2;
part1 = path.Substring(0, 3); //C:\\
part2 = path.Substring(3 // File\Test
var fseArgs = new FileSystemEventArgs(WatcherChangeTypes.Deleted, part1, part2);
onDeleted(path,fseArgs); //FileWacther Delete method
Presumably
onDeletedis your own method. What does that do? I would expect it to quite possibly be simpler to have another method which wasn’t related toFileSystemEventArgs, call that directly in your “scenario”, and then make yourFileSystemEventWatcherhandler call it too. Avoid coupling toFileSystemEventWatcherwhen you don’t really need it.Additionally, you shouldn’t just use
Substringlike this to perform file system path manipulation – it ends up being very brittle. I strongly suggest you use the methods inPath.On the other hand, you haven’t really told us much about your context…