Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
i am developing an on line exam module in ASP.net with C#. I used timer control for stop watch. I want to stop timer when browser windows is close. Please help me.

Thanks for Advance.
Posted
Updated 22-Jan-13 19:18pm
v2
Comments
Rajiv.net40 22-Aug-16 5:55am    
how to run timer 24/7 when browser window is closed or opend in asp.nety with C#

1 solution

When it is closed, the timer does not exist anymore. Nothing to worry about.

You should understand what happens when you close the window. From the standpoint of the server part — nothing, unless you intentionally send some HTTP request (think Ajax).

You can do it if you capture "before unload" event. Please see: http://msdn.microsoft.com/en-us/library/ie/ms536907%28v=vs.85%29.aspx[^].

It's good to do via jQuery: http://msdn.microsoft.com/en-us/library/ie/ms536907%28v=vs.85%29.aspx[^].

—SA
 
Share this answer
 
v2
Comments
rahemani_1200 23-Jan-13 1:22am    
but after close browser window again i run my module timer start timing its previous values. Hence i am worried about it.
Sergey Alexandrovich Kryukov 23-Jan-13 1:29am    
Your timer is lost. You worry for a good reason, all right. You should understand that the whole lifetime of your server-side code lies between a single HTTP request and ends with HTTP response it generate. You can use session variables to persist in between. HTTP is stateless, which is its main limitation, a tough one.
—SA

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