string connectionstring = "server =SQLVS2\\SQLVS2;database=DDM;Persist Security Info=True;uid=ddmuser;password=User02+Ddm;";
    SqlConnection myConnection = new SqlConnection(connectionstring);
    SqlCommand myCommand = new SqlCommand("GetNullHash", myConnection);
    myCommand.CommandType = CommandType.StoredProcedure;
    myConnection.Open();
    SqlDataReader rdr = myCommand.ExecuteReader();

   while (rdr.Read())
    {
        string filename = @"\\" + rdr.GetString(3);
        filename = System.IO.Path.Combine(filename, rdr.GetString(2));
        filename = System.IO.Path.Combine(filename, rdr.GetString(1));
        computeHashh1 abc = new computeHashh1();
        Console.WriteLine(abc.computeHash(filename));
        inserthash insert = new inserthash();
       insert.InsertHash(rdr.GetString(1), abc.computeHash(filename), rdr.GetStr(2),rdr.GetString(3));

    }

我如何才能使此循环在5秒钟内永远运行一次,直到停止。

最佳答案

最简单的方法是:

while (true) {
    // code here
    Thread.Sleep(5000);
}

但是,为了提高鲁棒性,我建议使用windows serviceproper timer

关于c# - 我如何在5秒内进行无限循环,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11632419/

10-10 18:28