public static void Main(string[] args) { var factory = new SingularityFactory(); var singularity = factory.GetSingularity(); var job = new SimpleParameterizedJob <string>((parameter, scheduledTime) => Console.WriteLine($"{parameter}\tscheduled: {scheduledTime.ToString("o")}")); var schedule = new EveryXTimeSchedule(TimeSpan.FromSeconds(1)); var scheduledJob = singularity.ScheduleParameterizedJob( schedule, job, "Hello World", true); //starts immediately var startTime = DateTime.UtcNow.Add(TimeSpan.FromSeconds(5)); var schedule2 = new CronSchedule("* * * * * * *"); var scheduledJob2 = singularity.ScheduleParameterizedJob( schedule2, job, "Hello World 2", startTime); var scheduledJob3 = singularity.ScheduleParameterizedJob( new RunOnceSchedule(TimeSpan.FromSeconds(3)), job, "Hello World 3", false); singularity.Start(); Task.Delay(10 * 1000).Wait(); singularity.StopScheduledJob(scheduledJob); Task.Delay(5 * 1000).Wait(); singularity.Stop(); Console.ReadKey(); }
public static void Main(string[] args) { Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); Console.WriteLine("Program Start"); var raven = new Entity.AccountBinding() { AccountId = "f56d42b3-a75a-4eb0-885f-8b7a738581b9", EnableSSL = true, Mail = "*****@*****.**", Port = 993, Server = "imap.qq.com", Token = "nnofhlbubmhbbcib", Type = MailBindingType.Imap }; var singularity = Singularity.Instance; var job = new SimpleParameterizedJob<AccountBinding>((user, scheduledTime) => { FetchUnseen(user); Console.WriteLine($"scheduled: {scheduledTime.ToString()}"); }); var schedule = new EveryXTimeSchedule(TimeSpan.FromMinutes(1)); var scheduledJob = singularity.ScheduleParameterizedJob(schedule, job, raven, true); singularity.Start(); Console.WriteLine("Press to Exit"); Console.ReadKey(); }
static void Main(string[] args) { var singularity = Singularity.Instance; if (args.Length == 0) { Console.WriteLine("Executable path is required as first argument"); return; } string executablePath = args[0]; if (!System.IO.File.Exists(executablePath)) { Console.WriteLine("The executable file from arguments is not found :" + executablePath); return; } executablePath = System.IO.Path.GetFullPath(executablePath); Console.WriteLine("Executable path: " + executablePath); var job = new SimpleParameterizedJob <string>((parameter, scheduledTime) => { Console.WriteLine($"{parameter} \t Trigger Started : {DateTime.Now}"); System.Diagnostics.Process.Start(executablePath); Console.WriteLine($"{parameter} \t Trigger Completed : {DateTime.Now}"); }); var schedule = new EveryXTimeSchedule(TimeSpan.FromMinutes(30.25)); //var scheduledJob = singularity.ScheduleParameterizedJob( // schedule, job, "Hello World", true); //starts immediately DateTime startTime = DateTime.UtcNow; int initialDelayInMinutes = 0; if (args.Length > 1) { startTime = DateTime.UtcNow.Add(TimeSpan.FromSeconds(int.TryParse(args[1], out initialDelayInMinutes) ? initialDelayInMinutes * 60 : 0)); } Console.WriteLine("Initial Delay for job (in minutes): " + initialDelayInMinutes); Console.WriteLine("Job starts at (in minutes): " + startTime.AddMinutes(330)); var scheduledJob2 = singularity.ScheduleParameterizedJob(schedule, job, "Vote Every 30 min Job ", startTime); singularity.Start(); Thread.Sleep(10 * 1000); //singularity.StopScheduledJob(scheduledJob); string s = string.Empty; do { Thread.Sleep(5 * 1000); s = Console.ReadLine(); } while (s != "y"); if (s == "Y") { singularity.Stop(); } }