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));
}
how can i make this loop run once in 5 seconds for ever or untill stopped.
The simplest method would be:
while (true) {
// code here
Thread.Sleep(5000);
}
However, for more robustness, I would recommend a windows service with a proper timer.
I would wrap your code and use a timer object which will allow you to have control on the timer itself (stop,start,etc)
System.Timers.Timer aTimer;
aTimer = new System.Timers.Timer();
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
aTimer.Interval = 2000;
aTimer.Enabled = true;
private void OnTimedEvent(object source, ElapsedEventArgs e)
{
//your code
}
more info at
http://msdn.microsoft.com/en-us/library/system.timers.timer%28v=vs.100%29.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With