Click here to Skip to main content
16,022,538 members

Comments by Ashutosh Tripathi (Top 2 by date)

Ashutosh Tripathi 26-Jan-15 10:20am View    
static void Main(string[] args)
{


//Time when method needs to be called
var DailyTime = "18:51:00";
var timeParts = DailyTime.Split(new char[1] { ':' });

while (true)
{

var dateNow = DateTime.Now;
var date = new DateTime(dateNow.Year, dateNow.Month, dateNow.Day, int.Parse(timeParts[0]), int.Parse(timeParts[1]), int.Parse(timeParts[2]));
TimeSpan ts;
if (date > dateNow)
{
ts = date - dateNow;
}
else
{
date = date.AddDays(1);
ts = date - dateNow;
}

//waits certan time and run the code
Task.Delay(ts).Wait();
SomeMethod();

}
}



static void SomeMethod()
{
Datalayer obj = new Datalayer();
obj.AutoCalculate();

}

public void AutoCalculate()
{
var t = from a in da.tree_details
where a.userid=="RA1051"
select a;
foreach (tree_detail k in t)
{
k.lcount = 10;
}
da.SubmitChanges();
}
Ashutosh Tripathi 26-Jan-15 9:56am View    
I am making a website in which i need to automatically call some method at 23:59 and update database. please help.