469,282 Members | 2,123 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

Timer not getting enabled after disabling?

Greetings,

I have a routine I was running in VB6 on a timed schedule. When the
timeframe came up, the timer would be disable, the routine would run,
and the timer gets enabled. I am trying to migrate this project to
vb.net. But when the timer gets disable it is not getting re-enabled
after the routine is completed. I added Application.DoEvents just
before the call to Timer1.Enabled = True. But that did not help. Is
there something else I need to do to re-enable the timer?

Thanks,

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #1
4 2641
Can you post the code that's doing the disabling and enabling? Also, are
you using a Timer control or one of the other timers?

--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Rich P" <rp*****@aol.com> wrote in message
news:OV**************@TK2MSFTNGP14.phx.gbl...
Greetings,

I have a routine I was running in VB6 on a timed schedule. When the
timeframe came up, the timer would be disable, the routine would run,
and the timer gets enabled. I am trying to migrate this project to
vb.net. But when the timer gets disable it is not getting re-enabled
after the routine is completed. I added Application.DoEvents just
before the call to Timer1.Enabled = True. But that did not help. Is
there something else I need to do to re-enable the timer?

Thanks,

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 21 '05 #2


Private Sub Timer1_Tick(...)
If boolStart = False Then
boolStart = True
runProc()
Timer1.Enabled = False
End If
End Sub

Private Sub Timer2_Tick(...)
If d1.TimeOfDay = "16:00:00" Then
Timer1.Enabled = True
End If
End Sub

runProc() runs a bunch of DTS Packages at a certain time. Right now I
added another boolean var to invoke runProc() and to turn it off.
Timer1 will enable if I don't have any procedures to run. But if I have
to invoke a procedure then Timer1 won't enable again. I got it to work
with the boolean var

Private Sub Timer1_Tick(...)
If boolStart = False Then
If boolRunProc = True Then
boolStart = True
runProc()
End If
End If
End Sub

This sort of works, but I think I would rather disable the timer and
then re-enable it. Maybe I need to use an event handler?


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #3
Rich,

I do not know if you can do this sample I made a short while ago, it is
about a splash form, however there are a lot of timers in it

Keep in mind that there are 4 timers by the way
windows.forms.timer
system.timers.timer
threading.thread.timer
and a Microsoft.VisualBasic one

\\\form1 needs 2 textboxes and a button
Private WithEvents frm As Form2
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim timer1 As New System.Windows.Forms.Timer
'You can drag it as well to your form, than those directcasts you
see are not needed
AddHandler timer1.Tick, AddressOf mytimer1
'this can as well be done using the 2 comboboxes on the codelayout
TextBox1.Text = "0"
timer1.Enabled = True
timer1.Interval = 400
Dim timer2 As New System.Windows.Forms.Timer
End Sub
Public Sub mytimer1(ByVal sender As Object, _
ByVal e As System.EventArgs) 'this is the event what is done when the
time elapsed
TextBox1.Text = (CInt(TextBox1.Text) + 1).ToString
DirectCast(sender, System.Windows.Forms.Timer).Enabled = True
'sender is the object of the timer
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
frm = New Form2
frm.Show()
frm.Top = Me.Top
frm.Left = Me.Left + 200
End Sub
Private Sub f_form2ready(ByVal message As String) _
Handles frm.form2ready
TextBox2.Text = message
frm.Dispose()
End Sub
///
\\\form2 needs one textbox
Friend Event form2ready(ByVal message As String)
Private Sub Form2_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim timer1 As New System.Windows.Forms.Timer
AddHandler timer1.Tick, AddressOf mytimer1
'this can as well be done using the 2 comboboxes on the codelayout
timer1.Enabled = True
timer1.Interval = 300
End Sub
Public Sub mytimer1(ByVal sender As Object, _
ByVal e As System.EventArgs)
Static counter As Integer = 0
Dim mystring As String = "I am searching for the time "
TextBox1.Text = mystring.Substring(counter)
DirectCast(sender, System.Windows.Forms.Timer).Enabled = True
'sender is the object of the timer
counter += 1
If counter = 22 Then
DirectCast(sender, Timer).Enabled = False
RaiseEvent form2ready(Now.TimeOfDay.ToString)
Else
Me.Opacity -= 0.04
DirectCast(sender, Timer).Enabled = True
'Sender is the object of the timer
End If
End Sub
///(I have this sample as well with a thread however that is not your
question

I hope this helps a little bit?

Cor
Nov 21 '05 #4
It turns out that I was just being a little too impatient. The timer
did come back on, but I had to wait a little bit longer. Thanks for
your suggestions, though.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Peter Johnsson | last post: by
4 posts views Thread by Peter Oliphant | last post: by
2 posts views Thread by John David Thornton | last post: by
3 posts views Thread by Steve Lowe | last post: by
11 posts views Thread by Hotrod2000 | last post: by
8 posts views Thread by sony.m.2007 | last post: by
2 posts views Thread by Johnny Jörgensen | last post: by
18 posts views Thread by navyjax2 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.