如何使用ElapsedEventHandler手动触发事件?

时间:2014-03-14 10:01:19

标签: c# .net

如何手动触发正在用作事件的方法ElapsedEventArgs

// this run every X minutes

int periodMilliSeconds = periodMinutes * 60000;
timerStatus = new System.Timers.Timer(periodMilliSeconds);
timerStatus.Elapsed += new ElapsedEventHandler(OnTimerStatus);



// But I need to run this method at user interaction even Elapsed has not being fired
// Method to call pro grammatically not from the Timer

private static void OnTimerStatus(object source, ElapsedEventArgs e)
{
}

1 个答案:

答案 0 :(得分:1)

如果您不需要,可以使用空参数调用方法。

// Somewhere else
OnTimerStatus(null, null);