PC Review


Reply
Thread Tools Rate Thread

How to Control Timer Event?

 
 
Mr. B
Guest
Posts: n/a
 
      13th Nov 2004
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
 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWl0Y2hlbGw=?=
Guest
Posts: n/a
 
      13th Nov 2004
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
>

 
Reply With Quote
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      13th Nov 2004
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).TotalMilliseconds)

Hope this helps
Jay

"Mr. B" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
Guest
Posts: n/a
 
      13th Nov 2004
Define "doesn't work". That is precisely how you turn the (12-second) timer
off. Do you get an error?

Jeff
"Mr. B" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Close Access, or Timer/Timer Event Help =?Utf-8?B?V2VuZHk=?= Microsoft Access VBA Modules 2 16th Apr 2007 03:54 AM
Trying to control the visibilty property of panel in timer event ravidhixith@gmail.com Microsoft ASP .NET 2 10th Mar 2006 05:04 AM
How to Control Timer Event? Mr. B Microsoft Dot NET 3 13th Nov 2004 11:28 PM
App sporadically hangs while raising event while processing system.threading.timer event Dan Microsoft Dot NET Compact Framework 6 25th Oct 2004 09:38 PM
App sporadically hangs while raising event while processing system.threading.timer event Dan Microsoft C# .NET 6 25th Oct 2004 09:38 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:53 AM.