我想在C#2005中开发的winform程序中手动触发ontimer事件,但是不知道要传递的参数是什么,所以总提示错误,请诸位大虾帮帮忙!现在写的调用代码如下,有错误......
System.Timers.ElapsedEventArgs e =new System.Timers.ElapsedEventArgs();
this.OnTimer(this,e);
......请问正确的调用方法应该如何?
System.Timers.ElapsedEventArgs e =new System.Timers.ElapsedEventArgs();
this.OnTimer(this,e);
......请问正确的调用方法应该如何?
试试应该可以的。
{
// Fields
private DateTime signalTime; // Methods
internal ElapsedEventArgs(int low, int high); // Properties
public DateTime SignalTime { get; }
}
关闭的时候直接
time1.Stop();或者time1.Enabled=false;
调用完一次ontimer函数以后,在把轮询周期设为原来的。
这样应该可以的。
把e声明成 EventArgs,表声明成派生类
这样就应该没有错误了
很方便。
如果需要就很不幸了,ElapsedEventHandler根本没有构造函数,你的需求是无法做到的。其实很奇怪你为什么不用 System.Windows.Forms.Timer而一定要用System.Timers.Timer。我看到这个帖子才知道有这么个东西呢
前者比后者精确,这个程序我从同事手里接过来的,timer控件已经加入了,以为使用上没啥区别呢,所以就没改。
另外如果是System.Windows.Forms.Timer我的想法就能够实现了吗?如何做?
或者你把OnTimer的全部内容进行重构->提取方法,直接调用提取出来的方法也一样...