Fire Hand
Fire Hand

Reputation: 26346

Keep timer running in the background

I was thinking to create a timer to display the elapsed time for a long running task in my asp.net application. I was able to create the timer to run using javascript but i have a problem with it, that is, how can i maintain the elapsed time so that even the user navigate away from the page, the timer will still running and when user return to that page again, he/she still can see the timer running. Beside that, another user that access that page from another computer will also see the timer running. How i can achieve this??

Upvotes: 1

Views: 628

Answers (1)

David
David

Reputation: 1970

If you want to have the timer persist after they navigate away from the page, and for other users then it will need to be server-side. ie. Not JavaScript but written in the code of your ASP.NET website.

Maybe when you start your long-running task you could add a Date Object into the Application's state and then whenever you have a page that you want to display the elapsed time you only need to read that variable back from the application and display the time difference.

Once the long-running task is finished then you can remove the Date Object (by setting it to Null/Nothing ) and that will signify that the process has finished.

Upvotes: 1

Related Questions