C# Timer For Event Handler
I currently have the following event handler
WqlEventQuery query = new WqlEventQuery("__InstanceModificationEvent",
new TimeSpan(0, 0, 1), "TargetInstance ISA \"Win32_NetworkAdapterConfiguration\"");
ManagementEventWatcher even开发者_StackOverflow社区tWatcher = new ManagementEventWatcher(query);
eventWatcher.EventArrived += new EventArrivedEventHandler(eventArrived);
eventWatcher.Start();
private void eventArrived(object sender, EventArrivedEventArgs e)
{
//Event Codes
}
I need help in developing a (one time) timer. Here is how it should work.
- When there is an event,the timer would start to run!
- Because there may be many occurrences of the event,if the timer has started,do not start the timer again ! (one time)
- Timer Duration Shall Be 5 seconds
- During the time(5seconds),the timer event must enumerate if the connection status of the network adapters.
Everyone's advice/help/suggestions/solution regarding this question would be deeply appreciated. I am confused with the mechanism of a (one time) timer !
Maybe this pseudo code helps:
myTimer.Interval = 5000;//5s
private void eventArrived(object sender, EventArrivedEventArgs e)
{
if(!myTimer.Enabled) //if timer not running
myTimer.Start();
}
private void myTimer_Tick(object sender, System.EventArgs e)
{
//enumerate statuses every 5s
}
精彩评论