C#调用计时器方法 [英] C# calling a timer method
本文介绍了C#调用计时器方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
然后我想调用一个方法(计时器方法(专用void timer1_Tick(object sender,EventArgs e)
通过此方法(启动方法)
我称此解决方案
受保护的 覆盖 void OnStart(字符串 [] args)
{
timer1_Tick( this ,e);
}
但是当我打电话时出现一个错误:
名称"e"在当前上下文中不存在
有解决方案吗?
解决方案
您好,
计时器需要一个名为"e"的EventArgs.
您没有名称为"e"的对象.
您可以像这样调用方法:
timer1_Tick(this,EventArgs.Empty);
是的,不要尝试传递不存在的东西.如果无法确定错误是正确的,那么我就茫然不知所措,因为您认为您正在使用编译器.
如果需要事件参数而没有事件参数,则使用EventArgs.Empty,这很明显.真正的程序员会考虑做某事的方法,并在您的计时器滴答声中调用它,而不是在计时器滴答声中调用它来做点什么,但这又是另一回事了.hi i have a method with one arguement (at the service application & on statrt(string[] args method)
then i want to call a method (timer method (private void timer1_Tick(object sender, EventArgs e)
via this (start method)
i call this solution
protected override void OnStart(string[] args ) { timer1_Tick(this , e); }
but when i call one error occurs:
the name ''e'' does not exist in the current context
any have a solution?解决方案Hello,
the Timer requires an EventArgs called ''e''.
You dont have an objekt with the name ''e''.
You can call the Method like this:
timer1_Tick(this, EventArgs.Empty);
Yes, don''t try to pass something that does not exist. If you can''t work out that the error is correct, then I am at a loss what it is you think you''re doing with a compiler.
EventArgs.Empty is what you''d use if you need event args and don''t have any, as is clearly the case here. A real programmer would factor out the method that does something, and call it in your timer tick, rather than call a timer tick to do something, but that''s another story.
这篇关于C#调用计时器方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文