"...software/git@code.it4i.cz:sccs/docs.it4i.cz.git" did not exist on "5c20d591a4316b5befad14ff3a2a2bde6bf480c2"
Newer
Older
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
using System;
using System.Threading;
using System.Timers;
using log4net;
using Timer = System.Timers.Timer;
namespace HaaSMiddleware.BackgroundThread.Tasks {
internal abstract class AbstractTask : IBackgroundTask {
protected readonly ILog log;
private readonly Timer taskTimer;
public AbstractTask(TimeSpan interval) {
this.log = LogManager.GetLogger(this.GetType().ToString());
this.taskTimer = new Timer(interval.TotalMilliseconds);
this.taskTimer.Elapsed += taskTimer_Elapsed;
}
public void StartTimer() {
this.taskTimer.Start();
}
public void StopTimer() {
this.taskTimer.Stop();
}
private void taskTimer_Elapsed(object sender, ElapsedEventArgs e) {
// Run the task in its own thread
Thread thread = new Thread(delegate() {
try {
RunTask();
}
catch (Exception ex) {
log.Error("An error occured during execution of the background task: {0}", ex);
}
});
thread.Name = "Timer - " + this.GetType().ToString();
thread.Start();
}
protected abstract void RunTask();
}
}