I have created a thread in my c# application. its code is given below.
[WebMethod]
public void start()
{
Thread thread = new Thread(new ThreadStart(WorkThreadFunction));
thread.Start();
}
[WebMethod]
public void stop()
{
Thread thread = new Thread(new ThreadStart(WorkThreadFunction));
thread.Abort();
}
public void WorkThreadFunction()
{
try
{
TimeZone zone = TimeZone.CurrentTimeZone;
DateTime dt = DateTime.Now.AddHours(12);
dt = dt.AddMinutes(30);
TimeSpan offset = zone.GetUtcOffset(DateTime.Now);
String s = "insert into tb_log(timestamp) values('" + dt + "')";
Class1 obj = new Class1();
string res = obj.executequery(s);
}
catch
{
}
}
When I run this code the value enters only at one time into the table. I need to execute this thread at 1 min intervals throughout the day, week and year. How to make this possible? Also correct me if the code which I had written is correct or not. I'm new to threads in c#. So someone please help me out. Thanks and Regards..