开发者

scheduling timers in c#

开发者 https://www.devze.com 2023-02-11 21:26 出处:网络
开发者_如何学GoAfter launching my application i want to run my application sometimes later and not immediately after launching it.How do i do it?Can i accept the time when i want to run my application

开发者_如何学GoAfter launching my application i want to run my application sometimes later and not immediately after launching it.How do i do it?Can i accept the time when i want to run my application,through the comand line.Please help.Thanx in advance.

Regards, Sanchaita sujit chakraborty


I don't understand exactly what you want to accomplish but Quartz.NET is a library that you can use to schedule jobs in .NET.


You can create a scheduled task programmatically by spawning schtasks: System.Diagnostics.Process.Start("schtasks", @"/create /tn mytask /tr C:\mypgm.exe /sc daily /st 18:55:00"); You can refer the schtasks doc to have more information on what you exactly need.


you can use System.Threading.Timer class to schedule a method call

static void Main(string [] args)
{
    DateTime? startDate = null;
    if(args.length>1) 
    {
        DateTime.TryParse(args[0], out startDate);
    }
    if(startDate.HasValue && DateTime.Now<startDate.Value)
    {
        System.Threading.Timer timer = new System.Threading.Timer(new TimerCallback(StartProgram));
        timer.Change(startDate.Value.Substract(DateTime.Now).TotalMilliseconds, Timeout.Infinite);
    }
    else
        StartProgram();
}
private static void StartProgram()
{
    Console.WriteLine("Started");
    //rest of you code
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号