gpt4 book ai didi

c# - 我怎样才能做一个有 5 秒暂停的无限循环

转载 作者:太空狗 更新时间:2023-10-29 19:50:46 24 4
gpt4 key购买 nike

    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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com