【发布时间】:2016-06-08 08:16:22
【问题描述】:
我想每隔 5 分钟交替调用两个方法,我该怎么做?
public class Program
{
static void Main(string[] args)
{
Console.WriteLine(" calling Method1 ");
/* After Next 5 minute call Method2 */
Console.WriteLine(" calling Method2 ");
Console.ReadLine();
}
private Method1()
{
Console.WriteLine("Method1 is executed at {0}", DateTime.Now);
Console.ReadLine();
}
private Method2()
{
Console.WriteLine("Method2 is executed at {0}", DateTime.Now);
Console.ReadLine();
}
}
感谢任何帮助。 谢谢..!
【问题讨论】:
-
@RahulHendawe 创建一个 exe 并使用 Windows 中的任务计划程序调用它。或者在其中创建一个 Windows 服务和计时器,间隔为 5 分钟。
-
@Alex:谢谢,任何使用计时器从 Windows 服务交替调用
first 5 min call method1 next 5 min call method2等方法的示例示例。 -
@Alex .exe 与任务计划程序将无法实现所需的结果(特别是交替方法调用)。 Windows 服务似乎有点矫枉过正,并且无法访问
System.Console,或任何 UI 线程交互。 OP 只需要一个Timer
标签: c#