Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi everyone,

I am new to development. I have implemented one web application. Here customer can run the .exe from clicking the one button.
We have huge number of user so we need to avoid the parallel accessing or running of exe . Please help me to implemented a locking mechanism to running the my .exe file in synchronize process (keeping in Q user requests)
Posted
Updated 19-Aug-14 2:13am
v2
Comments
ZurdoDev 19-Aug-14 11:53am    
You mention web application but then also mention .exe. Not the same thing. What are you talking about?

1 solution

Set up a database table with a single row and 2 fields, ID (tinyint will do) as primary key and Lock as, say, a nullable varchar.
Insert one row with ID of 1 and leave Lock null

In your code, within a try/catch block, in a loop, write an update query, updating Lock with a piece of unique information for that request (note you can make Lock a number if the unique information is numeric) where ID = 1 and Lock Is NULL
Now select the row and if Lock matches you unique information exit the loop
In the loop, after the test, sleep for a short period (say 10 milliseconds) to avoid blocking
After the loop execute your EXE
In the Finally of the try/catch block issue an update query to set lock to NULL where ID = 1 and Lock = unique information

The only danger with this approach is that somehow a process exits without ever clearing the lock. To solve this you could add a timestamp and run a scheduled job on your database to clear Lock after a timeout on that timestamp. If you are not using a DBMS server, test the timestamp in your loop and clear it if it has expired, but you still need to test to ensure that this process is the one that holds the lock.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900