Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello friends i am making exam application on vb.net i have added a timer of 20minutes on load event of form which contains questions but after loading the form the timer is not starting please give me some solution on why it is not starting. i as sending you the code which i wrote.

VB
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.alarmTime = Date.Now.AddMinutes(20)
        Me.Timer1.Start()
VB
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If alarmTime < Date.Now Then
            Me.Timer1.Stop()
            MessageBox.Show("Time's up.")
            Me.Button1_Click(sender, New System.EventArgs())
        Else
            Dim remainingTime As TimeSpan = Me.alarmTime.Subtract(Date.Now)

            Me.Label31.Text = String.Format("{0}:{1:d2}:{2:d2}", _
                                           remainingTime.Hours, _
                                           remainingTime.Minutes, _
                                           remainingTime.Seconds)
        End If
    End Sub
Posted
Comments
[no name] 7-Jun-13 0:59am    
Have you checked that the name Timer1 correct or you changed it in properties..
Sergey Alexandrovich Kryukov 7-Jun-13 1:11am    
The problem is not here. However, no one should use such sloppy names as "Timer1". They violate Microsoft naming conventions.
I put the solution, please see.
—SA
[no name] 7-Jun-13 1:14am    
I don't know, but can't we change it???
Sergey Alexandrovich Kryukov 7-Jun-13 1:40am    
Change? Why do you think VS has refactorization engine? It's very convenient. As to the naming conventions, please see FxCop.
I changed my answer...
—SA
Sergey Alexandrovich Kryukov 7-Jun-13 1:06am    
You did not show the timer creation and setting its period. The idea to combine timer and DateTime is quite bad.
What is "Date.Now"? There is System.DateTime.Now. But you don't need to use it, just the timer is enough.
Is it System.Timers.Timer or some other timer type?
(Generally, make sure that no relevant information is missing.)
—SA

Please see my comment to the question.

Use System.Timers.Timer:
System.Timers.Timer
[^].

Don't use System.DateTime with the timer. Simply set the timer's Interval property to 20 min.


[EDIT]

No, you need to use JavaScript timer. This should explain you what to do:
http://www.w3schools.com/js/js_timing.asp[^].

I don't even what to explain and think about what happens if you use the timer on the server-side. Just understand that all what server side does is: it accepts HTTP request and generates HTTP response. This is all the whole runtime of an ASP.NET page. Analyze it, and you should understand why what you did makes no sense at all.

—SA
 
Share this answer
 
v3
Comments
sachin bhise 7-Jun-13 1:31am    
i have entered the corrections still its not working
Sergey Alexandrovich Kryukov 7-Jun-13 1:36am    
Well, you did something wrong. Did you use the debugger?
Wait a second! This is ASP.NET! Using the timer on the server side is useless! Just think about Web operation. Isn't that obvious?
You need to use JavaScript timer.
—SA
insted of timer1.start() use timer1 . enable =true and timer1.stop() to timer1.enable=false
 
Share this answer
 
 
Share this answer
 
designed a new form and then added all the code in that form working excellently.....
but i know that's not a perfect solution will do R&D on the problem later
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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