A lot of actions in my ASP.NET app happen asynchronously (i.e in background threads without any access to HttpContext). Let me take an example of one such action. The app would be deployed to a web farm soon.
The background threads would be processing files deposited to a network share location. So, when the app starts, I create a FilesystemWatcher to monitor activities on the desired network share folder.
As soon as a new file arrives, the code processes it and marks it as completed processing.
The problem is with multiple servers watching the same network share, the same file might get processed on different machines, meaning redundant results. On a single server, I use locking mechanisms to prevent race conditions.
Now how to prevent the same on a web farm??
I was thinking of using a database to avoid such race conditions. So, when a server gets notified of a change to the network share, it requests a lock on a database object. Having granted the lock, it checks if the file has been processed and if not processes
it, marks it as being processed and releases the lock. As all servers would be doing the same, they would not get into the processing logic for a file once it has been processed by another se
View Complete Post