Locked timer control woes

By hermiodinator ·
Hi guys, this is my first post so please be gentle

I`m having problems with the timer control that I hope people can help me out with.

Basically, i`m creating the timer control at runtime (full code at end of post) and it just will not work and I don't know why!

I've compared it to code used to control a design-time timer and they are practically identical (bar the timer generation code obviously). I've looked at some tutorials for creating timers at runtime and my code seems almost identical to theirs, I don't know what I`m doing wrong!

Here's the code:
inherits System.Windows.Forms.form

Dim tTimer As System.Timers.Timer

Sub Form2Load(ByVal sender As Object, ByVal e As EventArgs)

tTimer=New System.Timers.Timer
AddHandler tTimer.elapsed, AddressOf TimerFired

End Sub

Private Sub TimerFired(ByVal sender As Object, _
ByVal e As System.Timers.ElapsedEventArgs)

label1.Text = now.ToLongTimeString.tostring()

Sub Button1Click(ByVal sender As Object, ByVal e As EventArgs)
End Sub

Hope someone can help before I damage the computer!

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Collapse -

The only think I can think of is scoping

by Tony Hopkinson In reply to timer control woes
Collapse -

got it

by hermiodinator In reply to The only think I can thin ...

thanks for your reply Tony.

I got a working reply from another forum where I posted this problem.

All that is needed is to use the windows.forms.timer class instead of the system.timers.timer class and the code works fine.

Would never have believed it would be that simple. I didn't even realise there was more than one timer class in .net!

Collapse -

Hmm, somthing funny going on here

by Tony Hopkinson In reply to got it

Found this

Going to have an experiment tomorrow, not seeing anything that tells me why the code shouldn't have worked, short of system.timer not being passing the elapsed event to the foreground message queue, synchronisation maybe ?
Hmmm frankly puzzled.

Nice to know the distinction has such an impact though.

Cheers, serious dandruff creator that one if you aren't au fait.

Collapse -

Aha , threading it is

by Tony Hopkinson In reply to Hmm, somthing funny going ...

Try update a windows control from a system.timer and in VS2005 you get told off because the timer is in a diferent thread.

For the curious, here's the help link on the exception


Collapse -

Edited by moderator

by kylej In reply to timer control woes


Message was edited by: beth.blakely@...

Related Discussions

Related Forums