473,388 Members | 1,335 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,388 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 21 '05 #1
6 1301
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 21 '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 21 '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 21 '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 21 '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 21 '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 21 '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: 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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.