I want to create a web page where users can initiate a process, this process will take several minutes to complete.
My question is:
When the user clicks on a button, should I start the process on a different thread and send him to a different page? I don’t want the process to end in case he closes the window or the connection is lost.
Also how can I prevent other users from initiating this process.
I thought about putting a variable in the application state that indicates whether the process is currently running or not.
Thanks for your advices
You could spawn a thread that is going to do the work and periodically checks whether it should still continue with his work. For the work you generate a certain ID (that you may or not couple to the user for extra security) that will be used to distinguish the work job. On the redirected page you could use some javascript to tell the server that the user is still waiting for job with ID X. Should this time-out expire you can drop the work.
for the result
the client you can pass the information to the client.
Update: If you want only one person to activate the process then you could still use the still system if you want to keep a history of some kind. You would only need to change the landing page to always look at the latest process and prevent other from starting one if there is still a process running.
Otherwise you could do the same as in the above system but use a single store point for the process results. If the store point consists a placeholder it indicates that the process already has been started and that no-one should start a new process. The display page could then poll against this store point for the info to show the users.
In the event you want everyone to be able to see the current results while a new process is being executed use two locations to store the result, one to store the finished one and one to store the busy one.