Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#-循环方法,并在它们之间放置延迟_C#_.net_Windows_Loops_Methods - Fatal编程技术网

C#-循环方法,并在它们之间放置延迟

C#-循环方法,并在它们之间放置延迟,c#,.net,windows,loops,methods,C#,.net,Windows,Loops,Methods,我有几个在Main方法中声明的方法 虽然我怎样才能放入一个循环,所以在本例中OutputChanges()将循环到FileChanges()。是否可以在循环之间设置一个中断/间隔(比如10秒) static void Main(string[] args) { FileChanges(); FolderChanges(); OutputChanges(); } 您没有提到要循环

我有几个在Main方法中声明的方法

虽然我怎样才能放入一个循环,所以在本例中OutputChanges()将循环到FileChanges()。是否可以在循环之间设置一个中断/间隔(比如10秒)

 static void Main(string[] args)
        {


            FileChanges();

            FolderChanges();

            OutputChanges();

        }


您没有提到要循环多少次……因此我将使用无限循环(用于在迭代之间暂停执行10秒):

你可以做:

static void Main(string[] args)
{

  while(true)
  {
     FileChanges();
     FolderChanges();
     OutputChanges();
     Thread.Sleep(10000);
  }

}
static void Main(字符串[]args)
{
int计数器=0;
做{
计数器++;
FileChanges();
FolderChanges();
OutputChanges();
睡眠(10000);

}while(counter我建议改为使用a。计时器可以每10秒滴答一次,此时您可以进行操作。

我想他希望在OutputChanges()之后暂停;而且只有一次停顿。@Jamie:那他就可以移动那条线了。我看不出问题中有任何关于睡眠应该在什么时候发生的规定,只是每次迭代都应该如此。你可能是对的,但我希望OP可以改变他的目的。我不确定为什么有人会以“不是真正的问题”来结束这个问题。这可能是个基本问题,但肯定是个真正的问题,所以不要歧视那些可以通过谷歌快速搜索得到答案的问题。谢谢你,先生,你是一个学者
static void Main(string[] args)
{
    while(true)
    {
        FileChanges();
        FolderChanges();
        OutputChanges();

        Thread.Sleep(10000);
    }
}
static void Main(string[] args)
{

  while(true)
  {
     FileChanges();
     FolderChanges();
     OutputChanges();
     Thread.Sleep(10000);
  }

}
static void Main(string[] args)
{
    int counter=0;
    do{
        counter++;
        FileChanges();
        FolderChanges();
        OutputChanges();
        Thread.Sleep(10000);
    }while(counter<10)
}