The setup is this:
Whenever an error occurs on my website, an error-site is being displayed while an e-mail is being sent to the administrator.
The website show a lot of live statistics automaticly updated every 15 second via AJAX and XML. But the statistics are only calculated once every 15 second, no matter how many users there is. This is done by a timestamp hidden ind the MSSQL database:
IF the timestamp is NOT older than 15 seconds, the second step is being skipped.
Now my problem is, that if 2 users makes the timestamp request at the same time then the system doesn't have the time to update the timestamp before both of the users tries to update the XML document, causing one of them to fail with the error message:
msxml3.dll (0x80070020) The process cannot access the file because it is being used by another process. /file.asp, line 310
Is it possible to check if the process is being used BEFORE trying to save the XML document? Or maybe ignoring this explicit kind of error?
I think that a simple lock will solve your issue.
In classic ASP lock can be achieved using the Application object by setting top level application variable.
In the code running the calculation make those changes:
If Application("Calculation_Lock")<>"" Then Application("Calculation_Lock") = Now() 'do the calculation... 'calculation in progress... 'calculation in progress... 'calculation in progress... 'when it's all done: Application("Calculation_Lock") = "" End If
Initially, the application level variable will be empty so the first user will enter the If statement, then assign the lock. Any further requests will be ignored while the lock is active i.e. the application level variable is set.
There is risk of the lock staying active forever in case of error during calculation, so to play it safe you can compare the value (which is the time when the lock was set) and the current time and if more than X seconds/minutes passed manually release the lock.
User contributions licensed under CC BY-SA 3.0