I have a multi threaded C# application which creates files, opens them for processing, then deletes them once finished. This application can expect anywhere from 1 - 100 files to be processed. Somewhat randomly (most likely attributed to the multi threaded nature of the application) I get a sharing violation when I try to delete a file after processing. My gut says, well Vic, you didn't properly close/dispose the file before trying to delete it. And I would go with my gut if it happened for every file, but it doesn't. So, I'm trying to find out where I'm making a mistake. Anyone out there have any pointers on how to debug this type of an exception? I would love to see a stack trace on the file if that makes sense.
I'll attempt to show pseudo code, however, my question is more on how to debug this type of exception:
Application Events:
Operation Start += Create new processor.
Transfer File += Processor.ProcessFile and Add new Document object to Processor's Document collection (as path, not file)
Operation complete += Processor.Aggregate files, create new File containing contents of files. When this method is finished, it calls ProcessorFinished.
Processor Events:
Processor Finished += Application_CleanUpProcessor. In this method, I dispose of the processor, which in turn disposes of a document object, which deletes the file.