My application deals with e-mails coming from different sources, e.g. Outlook and IMAP mailboxes. Before parsing them, I write them to the temporary directory (keeping them in memory is not an option). While parsing, I might be writing attachments to the temp directory (for example, if they are too large to keep in memory or for full-text extraction).
But in the wild, two things happen that seemed very strange in the first place but could all be traced back to virus scanner behaviour:
I'm sometimes unable to open files which I've written myself a few milliseconds ago. They are obviously locked by virus scanners to ensure that they are clean. I get an Exception.
If files are considered dangerous by the virus scanner, it deletes them at some point of time.
To cope with this behaviour, I've written a few methods that try again if open fails or do some checks if files exist, but I'm unable to use them in every part of the application (3rd party code, for example filters), so things got better, but not 100% perfect and my source code looks ugle in parts because of this.
How do you cope with virus scanners?