Anti-nuisance lawsuit warning: The purpose of these notes is to remind me, Zoegond, of stuff or to help me work stuff out. They may contain mistakes.

Quick

  • ($a, $b....) = unpack("A2A7...", $packed)
  • push( array, list )

Friday, April 30, 2010

.NET timers

To use a timer:

using System.Timers;
...
// NB put this next declaration at class level,
// not in a method where 'tick' will be
// garbage collected before it can fire
System.Timers.Timer tick;

...
tick = new System.Timers.Timer(10000);
// include the next line if you want event handler to interact with controls
// (eg setting text)
tick.SynchronizingObject = this;
tick.Elapsed += new ElapsedEventHandler(this.tickElapsed);
tick.Enabled = true;
...
void tickElapsed(object source, ElapsedEventArgs e)
{
...
}

If your timer is failing to eg set text on a control, check that you included the SynchronizingObject set.

Followers

Blog Archive