I have created one thread in C#. Now I want to put the thread that I created into some specific amount of time. And then I want to start my thread. My target is, I want to invoke my updateMark function daily at 8 PM. After invoking my function, then that thread will go to sleep for next 24hours. So it will again start at 8PM of the next day and do the same work routinely.
**My C# code:-**
public class ThreadProcess
{
public static void Main()
{
}
public void updateMark()
{
string temp=ok("hai");
}
public string ok(string temp)
{
return temp+"!!!!";
}
}
So, I am using thread in the following code in another class:
string targetTime = "08:05:00 PM";
string currentTime = DateTime.Now.ToString("HH:mm:ss tt");
DateTime t11 = Convert.ToDateTime(targetTime, culture);
DateTime t21 = Convert.ToDateTime(currentTime, culture);
ThreadProcess tp = new ThreadProcess();
Thread myThread = new Thread(tp.updateMark);
myThread.Start();
if (t11.TimeOfDay.Ticks > t21.TimeOfDay.Ticks)
{
TimeSpan duration = DateTime.Parse(targetTime, culture).Subtract(DateTime.Parse(currentTime, culture));
int ms = (int)duration.TotalMilliseconds;
//Thread.Sleep(ms);i want to put my thread into sleep
}
while (true)
{
myThread.start();
Thread.Sleep(86400000);//put thread in sleep mode for next 24 hours...86400000 milleseconds...
}
Please guide me to get out of this issue...