I have the following code in my windows service
var timeToWait = TimeSpan.FromSeconds(20);
var interval = TimeSpan.FromMinutes(5);
var t = new Timer((s) =>
{
tracker.ProcessAuditLogs();
}, null, timeToWait, interval);
Are there any ways I can monitor this timer, by polling or any other mechanisms, and get back information to display on a windows form, with information such as
There isn't a standard way with the Timer class. I would advise to encapsulate a timer object in a parent class like this :
public class MonitoredTimer {
private Timer _timer;
private int NextExecutionTime;
private int LastExecutionTime
public MonitoredTimer(TimerCallback callback,...) {
_timer = new Timer((s)=>callback(s);UpdateExecutionTimes());
}
public int GetLastExecution(){
return LastExecutionTime;
}
...
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.