-
Notifications
You must be signed in to change notification settings - Fork 0
/
TimedEvent.cs
executable file
·68 lines (58 loc) · 2 KB
/
TimedEvent.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* Contents of this file may be used in whatever manner pleases you the most. -Naman Kumar
*/
using System;
using System.Threading;
namespace com.nk.lib
{
class TimedEvent
{
/*
* A stand alone class that fires an event at a particular interval
*
* usage:
*
* -----instantiate
* TimedEvent event = new TimedEvent(int timeDelay, int fireInterval, object parameters)
*
* -----enable firing events
* event.eventTrigger += new TimedEvent.fireEvent(methodToBeCalledWhenTimerFired);
*
* public void methodToBeCalledWhenTimerFired(object sender, EventArgs e)
* {
* //Do something
* //Note the method signature...the method and delegate (fireEvent) signature MUST match
* //"object sender" can be used to pass any sort of information
* }
*
* -----stop timer
* event.disposeTimer();
*
* Version 1.0 by Naman Kumar, August 25,2009
*/
public delegate void fireEvent(object sender, EventArgs e);
public event fireEvent eventTrigger;
Timer eventFiringTimer;
public TimedEvent(int timeDelay, int fireInterval, object parameters)
{
eventFiringTimer = eventTimer(timeDelay, fireInterval, parameters);
}
private Timer eventTimer(int timeDelay, int fireInterval, object parameters)
{
return new Timer(new TimerCallback(callBack), parameters, timeDelay, fireInterval);
}
protected void OneventTrigger(object parameters)
{
if (eventTrigger != null)
eventTrigger(parameters, EventArgs.Empty);
}
private void callBack(object parameters)
{
OneventTrigger(parameters);
}
public void disposeTimer()
{
eventFiringTimer.Dispose();
}
}
}