在计算机上在后台连续运行c#程序
我以下面的代码为例,但想知道如何无限期地运行console.exe文件,但以五分钟为增量运行for循环在计算机上在后台连续运行c#程序,c#,C#,我以下面的代码为例,但想知道如何无限期地运行console.exe文件,但以五分钟为增量运行for循环 class Program { static void Main(string[] args) { for (int i = 0; i < 10; i++) { Console.WriteLine("hellow world");
class Program
{
static void Main(string[] args)
{
for (int i = 0; i < 10; i++)
{
Console.WriteLine("hellow world");
}
Console.ReadLine();
}
}
类程序
{
静态void Main(字符串[]参数)
{
对于(int i=0;i<10;i++)
{
Console.WriteLine(“hellow world”);
}
Console.ReadLine();
}
}
看看线程。睡眠:
Thread.Sleep(300000);
其中数字是要等待的毫秒数。不过,我不建议使用控制台应用程序来实现这一点。您是否考虑过创建windows服务?我会将其作为windows计划任务运行。这样,您就不必在自己的应用程序中重新实现所有调度选项。因此,步骤如下:
使用
while(true)
在5分钟后返回false。如何执行此操作您可以使用DateTime。现在使用获取当前时间,或者使用Stopwatch
类更精确。@user2543131-您当前的代码只循环10次。到达循环无限的点。你上一个问题的答案解释了如何做到这一点。你已经问了这个问题,并且已经接受了答案。你为什么又问?