473,394 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 2871
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Peter Johnsson | last post by:
How come the eventhandler for the timer's elapsed time event is called over and over again, even though the AutoReset property is set to false, if you assign a new value to the timer objects...
4
by: Peter Oliphant | last post by:
I'd like to be able to destroy a Timer in it's own event handler. That is, within it's tick handler I'd like to delete the Timer itself (e.g., for one-shot timers). Is this possible? In general,...
7
by: Noozer | last post by:
I have a timer on a form. It isn't firing at all. I know that the timer is enabled, and that the interval is low (4000, which should be 4 seconds). To ensure the timer wasn't being inadvertantly...
2
by: John David Thornton | last post by:
I've got a Windows Service class, and I put a System.Threading.Timer, and I've coded it as shown below. However, when I install the service and then start it in MMC, I get a peculiar message: ...
3
by: Steve Lowe | last post by:
Hi, I'm getting into VB.net with the help of a few books, but have got a problem grasping how to implement a system.timers.timer Only 1 of my 3 books mentions timers and that's a...
11
by: Hotrod2000 | last post by:
I'm quite new to programming but I'm having problems getting a timer to work in visual studio.net I've created a timer on a form, enabled it and then typed the following code (from the mdsn...
8
by: sony.m.2007 | last post by:
Hi, My application processes a file and updates the data into sql server. The process takes around 30-90 seconds.I decided to put a timer to display the user a label(making label visible false and...
2
by: Johnny Jörgensen | last post by:
I've got a process I want to run in a thread separate from my main application thread, so I've used a backgroundworker component, and in frmMain.Load I invoke the code using...
18
by: navyjax2 | last post by:
What if your event handler has to be nonstatic?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.