473,327 Members | 2,016 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,327 software developers and data experts.

How to Control Timer Event?

My current app has a timer that I kick ON in my Form1_Load as follows:

' Set Up the Timer Function
Dim t As New System.Timers.Timer(12000) ' 1000 = 1 Second
t.Enabled = True ' False to Turn OFF
AddHandler t.Elapsed, AddressOf TimerFired

This in turns fires up my sub called "TimerFired" every 2 minutes...

In this sub, I check a file for a change in the date/time and if I find a
difference (ie newer file date), I then continue on with the sub and does some
updating. Otherwise I end the sub and the timer continues on with it's
periodical check.

What I want to do is to "Stop" the Timer event 'when' the sub does it's
updating... then fire it back up when the 'stuff' finishes.

I've tried a few things such as:

Timer1.Enabled = False

in my Sub... but that doesn't work...

Any ideas out there?

Regards,

Bruce
Nov 22 '05 #1
6 3218
Mr B

I do some programming in java, c/c++ etc I have not done any
programming in VB yet, but I would assume the timer would execute in a
seperate thread than the main program is their a way to block/lock or suspend
the thread while processing the file?? can this be done in VB I don't know
Just a thought.

Cheers
Mitchell

"Mr. B" wrote:
My current app has a timer that I kick ON in my Form1_Load as follows:

' Set Up the Timer Function
Dim t As New System.Timers.Timer(12000) ' 1000 = 1 Second
t.Enabled = True ' False to Turn OFF
AddHandler t.Elapsed, AddressOf TimerFired

This in turns fires up my sub called "TimerFired" every 2 minutes...

In this sub, I check a file for a change in the date/time and if I find a
difference (ie newer file date), I then continue on with the sub and does some
updating. Otherwise I end the sub and the timer continues on with it's
periodical check.

What I want to do is to "Stop" the Timer event 'when' the sub does it's
updating... then fire it back up when the 'stuff' finishes.

I've tried a few things such as:

Timer1.Enabled = False

in my Sub... but that doesn't work...

Any ideas out there?

Regards,

Bruce

Nov 22 '05 #2
Mr B

I do some programming in java, c/c++ etc I have not done any
programming in VB yet, but I would assume the timer would execute in a
seperate thread than the main program is their a way to block/lock or suspend
the thread while processing the file?? can this be done in VB I don't know
Just a thought.

Cheers
Mitchell

"Mr. B" wrote:
My current app has a timer that I kick ON in my Form1_Load as follows:

' Set Up the Timer Function
Dim t As New System.Timers.Timer(12000) ' 1000 = 1 Second
t.Enabled = True ' False to Turn OFF
AddHandler t.Elapsed, AddressOf TimerFired

This in turns fires up my sub called "TimerFired" every 2 minutes...

In this sub, I check a file for a change in the date/time and if I find a
difference (ie newer file date), I then continue on with the sub and does some
updating. Otherwise I end the sub and the timer continues on with it's
periodical check.

What I want to do is to "Stop" the Timer event 'when' the sub does it's
updating... then fire it back up when the 'stuff' finishes.

I've tried a few things such as:

Timer1.Enabled = False

in my Sub... but that doesn't work...

Any ideas out there?

Regards,

Bruce

Nov 22 '05 #3
Bruce,
Any reason you are doing this with a timer rather then let a
System.IO.FileSystemWatcher notify you when the file changes?

What I do is set Timer.AutoReset to False, so the event does not
automatically fire. Then at the end of the Timer.Elapsed event handler I set
a new interval & set Timer.Enabled to True. Setting the interval should not
be needed, I do it as I have varying intervals that are based on other
factors...
Dim t As New System.Timers.Timer(12000) ' 1000 = 1 Second
This in turns fires up my sub called "TimerFired" every 2 minutes... Are you certain? It appears that your event will fire every 12 seconds.
Normally what I do is use a TimeSpan to calculate the interval.

Something like:

Dim ts As TimeSpan = TimeSpan.FromMinutes(2)
Dim t As New System.Timers.Timer(ts.TotalMilliseconds)

Or more succinctly:

Dim t As New
System.Timers.Timer(TimeSpan.FromMinutes(2).TotalM illiseconds)

Hope this helps
Jay

"Mr. B" <Us**@NoWhere.com> wrote in message
news:8f********************************@4ax.com... My current app has a timer that I kick ON in my Form1_Load as follows:

' Set Up the Timer Function
Dim t As New System.Timers.Timer(12000) ' 1000 = 1 Second
t.Enabled = True ' False to Turn OFF
AddHandler t.Elapsed, AddressOf TimerFired

This in turns fires up my sub called "TimerFired" every 2 minutes...

In this sub, I check a file for a change in the date/time and if I find a
difference (ie newer file date), I then continue on with the sub and does
some
updating. Otherwise I end the sub and the timer continues on with it's
periodical check.

What I want to do is to "Stop" the Timer event 'when' the sub does it's
updating... then fire it back up when the 'stuff' finishes.

I've tried a few things such as:

Timer1.Enabled = False

in my Sub... but that doesn't work...

Any ideas out there?

Regards,

Bruce

Nov 22 '05 #4
Bruce,
Any reason you are doing this with a timer rather then let a
System.IO.FileSystemWatcher notify you when the file changes?

What I do is set Timer.AutoReset to False, so the event does not
automatically fire. Then at the end of the Timer.Elapsed event handler I set
a new interval & set Timer.Enabled to True. Setting the interval should not
be needed, I do it as I have varying intervals that are based on other
factors...
Dim t As New System.Timers.Timer(12000) ' 1000 = 1 Second
This in turns fires up my sub called "TimerFired" every 2 minutes... Are you certain? It appears that your event will fire every 12 seconds.
Normally what I do is use a TimeSpan to calculate the interval.

Something like:

Dim ts As TimeSpan = TimeSpan.FromMinutes(2)
Dim t As New System.Timers.Timer(ts.TotalMilliseconds)

Or more succinctly:

Dim t As New
System.Timers.Timer(TimeSpan.FromMinutes(2).TotalM illiseconds)

Hope this helps
Jay

"Mr. B" <Us**@NoWhere.com> wrote in message
news:8f********************************@4ax.com... My current app has a timer that I kick ON in my Form1_Load as follows:

' Set Up the Timer Function
Dim t As New System.Timers.Timer(12000) ' 1000 = 1 Second
t.Enabled = True ' False to Turn OFF
AddHandler t.Elapsed, AddressOf TimerFired

This in turns fires up my sub called "TimerFired" every 2 minutes...

In this sub, I check a file for a change in the date/time and if I find a
difference (ie newer file date), I then continue on with the sub and does
some
updating. Otherwise I end the sub and the timer continues on with it's
periodical check.

What I want to do is to "Stop" the Timer event 'when' the sub does it's
updating... then fire it back up when the 'stuff' finishes.

I've tried a few things such as:

Timer1.Enabled = False

in my Sub... but that doesn't work...

Any ideas out there?

Regards,

Bruce

Nov 22 '05 #5
Define "doesn't work". That is precisely how you turn the (12-second) timer
off. Do you get an error?

Jeff
"Mr. B" <Us**@NoWhere.com> wrote in message
news:8f********************************@4ax.com...
My current app has a timer that I kick ON in my Form1_Load as follows:

' Set Up the Timer Function
Dim t As New System.Timers.Timer(12000) ' 1000 = 1 Second
t.Enabled = True ' False to Turn OFF
AddHandler t.Elapsed, AddressOf TimerFired

This in turns fires up my sub called "TimerFired" every 2 minutes...

In this sub, I check a file for a change in the date/time and if I find a
difference (ie newer file date), I then continue on with the sub and does some updating. Otherwise I end the sub and the timer continues on with it's
periodical check.

What I want to do is to "Stop" the Timer event 'when' the sub does it's
updating... then fire it back up when the 'stuff' finishes.

I've tried a few things such as:

Timer1.Enabled = False

in my Sub... but that doesn't work...

Any ideas out there?

Regards,

Bruce

Nov 22 '05 #6
Define "doesn't work". That is precisely how you turn the (12-second) timer
off. Do you get an error?

Jeff
"Mr. B" <Us**@NoWhere.com> wrote in message
news:8f********************************@4ax.com...
My current app has a timer that I kick ON in my Form1_Load as follows:

' Set Up the Timer Function
Dim t As New System.Timers.Timer(12000) ' 1000 = 1 Second
t.Enabled = True ' False to Turn OFF
AddHandler t.Elapsed, AddressOf TimerFired

This in turns fires up my sub called "TimerFired" every 2 minutes...

In this sub, I check a file for a change in the date/time and if I find a
difference (ie newer file date), I then continue on with the sub and does some updating. Otherwise I end the sub and the timer continues on with it's
periodical check.

What I want to do is to "Stop" the Timer event 'when' the sub does it's
updating... then fire it back up when the 'stuff' finishes.

I've tried a few things such as:

Timer1.Enabled = False

in my Sub... but that doesn't work...

Any ideas out there?

Regards,

Bruce

Nov 22 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: curious | last post by:
I am new to VB.NET and I need help in using timer control. Here is the scenario. I have 3 labels (label 1, label2, label 3), and a start button, all vertically aligned on the form. Using a...
4
by: William Bub | last post by:
Is there an accurate way to create a "stopwatch" good to 1/10 of a second? I'm not sure if I should use the timer control, or some way to access the computer timer. I found the following site...
3
by: David | last post by:
Hi There! I'm using Timer control to record how long my application perform certain tasks. However, apparently Timer control is not doing its' job (i.e. Not firing Tick event) while my...
3
by: Mr. B | last post by:
My current app has a timer that I kick ON in my Form1_Load as follows: ' Set Up the Timer Function Dim t As New System.Timers.Timer(12000) ' 1000 = 1 Second t.Enabled = True ' False to Turn OFF...
2
by: tom | last post by:
Hey All- For those of you having troubles with listviews appearing in the wrong position when on a tab control, we've come up w/one other workaround that may be useful. When you move to the...
3
by: Z D | last post by:
Hello, I've created a winform user control that, at some point in the default constructor, looks for a specifc file. When I try to load the user control to my winform's form during design time...
6
by: Steve | last post by:
I am working on a emulator and need to have time based events. I've tried to use the timer control and discovered that it runs waaaaaaay slow. I set the tick frequency to 1, then in the tick...
5
by: Sudharsan | last post by:
Hi I have developed a Windows Control Library in VC.NET The component will play back video files and this component is used in C# applications to display multiple videos simultaneously. The...
4
by: Chris Dunaway | last post by:
I have a main form with a "lock" button. When the lock button is clicked, another form is shown using ShowDialog(this). The user must enter their PIN on this form to close it and resume the main...
3
by: Steve | last post by:
Hi All I am using VB.net 2008 and use timer controls within my applications Question Does the code in a Timer control.tick event run on a different thread to the main Application thread (UI...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.