开发者

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.

  1. When there is an event,the timer would start to run!
  2. Because there may be many occurrences of the event,if the timer has started,do not start the timer again ! (one time)
  3. Timer Duration Shall Be 5 seconds
  4. 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
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜