This is a bit convoluted but I will try to explain as best as possible.
I'm using the FileSystemWatcher with a notify filter of
toFileWatcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.FileName;
I have a .Created method and a .Changed method.
When the .Created event fires it runs through some preliminary checks using the file name supplied from the watcher, checking to see if the file has been seen yet, getting a destination folder, and returning validation information.
I'm running into an issue where the validation is at the end of the .Created method and it accesses the file to do some validation before copying it on to its destination. When I get to this point, if the file is large and still in the process of copying from its source, it returns an io "file is already in use" error.
what I want to do is finish all of the preliminary code and then I want the thread to "hang" until the .Changed method for the file fires indicating that the file is done since i'm only catching the changes to the last access filter.
I would setup a separate thread using the producer-consumer pattern that watches for items to appear in a queue. These items will represent the file changes and include information like the path to the file and what kind of change occurred. Your FileSystemWatcher
event handlers will just post items to the queue and let the consumer thread dequeue and process the information. This will decouple the processing you require from the file system notification events where it will be easier to avoid to the "file in use" problems.