我想每天在我的 Windows 服务中检查许可证我尝试使用DispatcherTimer
但不工作这是我试图做的
public OIMService()
{
InitializeComponent();
_dispatcherTimer = new DispatcherTimer();
this.ServiceName = "OIMService";
if (!System.Diagnostics.EventLog.SourceExists("OIM_Log"))
{
EventLog.CreateEventSource("OIM_Log", "OIMLog");
}
EventLog.Source = "OIM_Log";
EventLog.Log = "OIMLog";
_sc = new ServiceController("OIMService");
_helpers = new ValidationHelpers();
StartTimer();
}
private void StartTimer()
{
_dispatcherTimer.Tick += new EventHandler(DispatcherTimerTick);
_dispatcherTimer.Interval = new TimeSpan(0, 0, Convert.ToInt32(time));
_dispatcherTimer.IsEnabled = true;
_dispatcherTimer.Start();
}
private void DispatcherTimerTick(object sender, EventArgs e)
{
var helpers = new ValidationHelpers();
if (!helpers.IsValid())
this.Stop();
}