My Win32 application performs numerous disk operations in the designated temporary folder during operation, and a serious redesign is out of the question.
Some clients have antivirus software that scans the same temporary directory (it just scans everything). We tried to talk to them about turning it off - it wonโt work, so itโs out of the question.
From time to time (something like once for every thousand file operations), my application tries to perform an operation on a file that is opened by antivirus at that time and therefore is blocked by the operating system. An exchange violation occurs and causes an error in my application. This happens approximately every three minutes on average.
A temporary folder can contain up to 100 thousand files in most typical scenarios, so I do not like the idea of โโconstantly opening them, because this can lead to exhaustion of resources in some boundary conditions.
Is there a reasonable strategy for my application to respond to situations where the required file is locked? Maybe something like this?
for( int i = 0; i < ReasonableNumber; i++ ) {
try {
performOperation(); // do useful stuff here
break;
} catch( ... ) {
if( i == ReasonableNumber - 1 ) {
throw; //not to hide errors if unlock never happens
}
}
Sleep( ReasonableInterval );
}
Is this a viable strategy? If so, how many times and how often should I repeat the application? What ideas are better if they are?
source
share