If your (.NET Micro Framework) application needs a regular, heartbeat-like event to function, MicroHeartBeat is for you. Set a period for the timer to trigger, add an event handler, and you're good to go.
This helper class was originally created for the AgentIntervals app. It's essentially just a wrapper around the stock Timer
class, but with several methods to add useful functionality.
Include the contents of the bin/Release folder in your project, and add a reference to MicroHeartBeat.dll
. Alternatively, just drop HeartBeat.cs
in your project.
public class ExampleClass
{
private static HeartBeat _heartBeat;
public static void Main()
{
// Events will trigger every 500 ms.
_heartBeat = new HeartBeat(500);
_heartBeat.OnHeartBeat += HeartBeatEventHandler;
_heartBeat.Start();
Thread.Sleep(Timeout.Infinite);
}
private static void HeartBeatEventHandler(object sender, EventArgs e)
{
// Include your logic here!
}
}
HeartBeat(int period)
: construct a new HeartBeat
that fires events every period milliseconds apart.
void Start()
: begins the heartbeat immediately.
void Start(int delay)
: waits delay milliseconds, then begins the heartbeat.
void Stop()
: stops the heartbeat.
bool Toggle()
: if the heartbeat is running, stops it and returns false
; if it is stopped, starts it immediately and returns true
.
bool Toggle(int delay)
: same as Toggle()
, but will wait delay milliseconds before starting the heartbeat.
void Reset()
: stops and restarts the heartbeat.
void Reset(int delay)
: stops the heartbeat, waits delay milliseconds, then starts it again.
void ChangePeriod(int period)
: changes the heartbeat to trigger every period milliseconds instead. If the heartbeat is running, stops and starts it again.
##License MicroHeartBeat is available under the MIT License.