本文介绍了我如何在5秒内进行无限循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    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秒钟内永远运行一次,直到停止.

how can i make this loop run once in 5 seconds for ever or untill stopped.

推荐答案

最简单的方法是:

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

但是,为了提高鲁棒性,我建议使用带有适当的计时器的Windows服务 .

However, for more robustness, I would recommend a windows service with a proper timer.

这篇关于我如何在5秒内进行无限循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-26 17:08