My application deals with emails coming from various sources, for example. Outlook and IMAP. Before disassembling them, I write them to a temporary directory (saving them in memory is not an option). During parsing, I can write attachments to the temp directory (for example, if they are too large for storage in memory or for full-text extraction).
But in the wild, two things happen that at first seemed very strange, but they could all be traced back to the behavior of viruses:
Sometimes I canβt open files that I wrote myself a few milliseconds ago. They are obviously blocked by antivirus scanners to make sure they are clean. I get an exception.
If the files are considered dangerous using an anti-virus scanner, it deletes them at some point in time.
To cope with this behavior, I wrote several methods that will try again if open fails or some checks if files exist, but I canβt use them in every part of the application (third-party code for example filters), so everything became better, but not 100% excellent, and because of this, the source code looks ugly.
How do you deal with antivirus scanners?
c # locking temporary-files antivirus
Stefan schultze
source share