RE: Timers not fireing System.Windows.Forms.Timer and System.Timer

From: Tim (TimWard_at_nospam.nospam)
Date: 08/18/04


Date: Wed, 18 Aug 2004 03:07:04 -0700

Aye, Changed the code (including the Timers that hadn't shown issues yet) and
been testing all morning.... no problems.

So It does appear to be a bug with AutoReset set True - I think it also
requires you to be changing the enabled state (or Start/Stop) inside the
elapsed event.

Thanks for your help Pedro.
Cheers Tim

(Another .Net bug worked arround only ..... many more left!)

"Pedro Gonçalves" wrote:

> Hi Tim,
>
> I've a workaround for that. I think that is a bug, but....
>
> Use a Timers.Timer. Set AutoReset property to False.
> Then at the Elapse event, do what you want to do and at the end call your
> timer Start sub.
> This just do the same you were doing.
>
> To test the bug and solve it, just add code at the begin of the Elapse event
> that test if the Enabled property is True. If it is, that means that you just
> found that exact time where your timer would stop firing. Has you set
> AutoReset property to False the Enabled property should be False every time
> that Elapse event fires. In this case, just change the Enabled property to
> False.
>
> Your's Elapse event code should look like this:
>
> Private Sub myTimer_Elapsed(ByVal sender As Object, ByVal e As
> System.Timers.ElapsedEventArgs) Handles myTimer.Elapsed
>
> ''''''''''''''''''''''''''''''''
> ' Workaround para bug do timer '
> ''''''''''''''''''''''''''''''''
> If myTimer.Enabled Then
> myTimer.Enabled = False
> End If
>
> Try
>
> ' Just add your event response code here.
> Catch ex As Exception
> ' Handle Exception
> End Try
>
> cTimer.Start()
> End Sub
>
>
> "Tim" wrote:
>
> > I have a problem with a Winform application (VB.Net) that timers just stop
> > firing.
> >
> > I first used System.Windows.Forms.Timer - which failed very often so I
> > replaced them with System.Timers.Timer and all appeared Ok till someone
> > started using two copies of the applcaition at the same time.
> >
> > I have seen it fail in the IDE (with another instance run manually) - the
> > event just stops fireing. If I break the applcation and check the timer is
> > still enabled. If I add a button to stop then start the timer.. if starts
> > fireing again for a couple of times then stops again!
> >
> > I have found similar posts on the newgroups and net foums but havn't seen a
> > single answer yet!
> >
> > Regards
> > Tim
> >