473,480 Members | 1,964 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 3234
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
23923
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
31203
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
1836
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
319
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
5297
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
2368
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
2196
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
372
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
7782
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
3846
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
7049
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
7092
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
6981
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5348
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4790
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4488
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3000
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2989
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
565
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.