static void Main() { var random = new Random(); var jobs = new Jobs { UseDequeue = true }; //Use false to test without proc var quit = false; var waiting = false; while (!quit) { var job = jobs.Dequeue(); if (job == null) { if (!waiting) { waiting = true; Console.WriteLine("Waiting for job..."); } continue; } waiting = false; Thread.Sleep(100 * random.Next(1, 20)); //do random work var data = (JobData) JsonConvert.DeserializeObject(job.Data, Type.GetType(job.Type)); try { jobs.Complete(job.Id); Console.WriteLine("Completed job '{0}' Name={1}", job.Id, data.Name); } catch (Exception ex) { Console.WriteLine("> ERROR: " + ex.Message); quit = true; Console.ReadKey(); } } }
private static void Main() { var jobs = new Jobs(); while (true) { Thread.Sleep(100); var data = new JobData { Name = DateTime.Now.ToString("u") }; var job = new Job { Id = Guid.NewGuid().ToString("N"), Created = DateTime.Now, Type = data.GetType().AssemblyQualifiedName, Data = JsonConvert.SerializeObject(data), }; jobs.Enqueue(job); Console.WriteLine("Created Job '{0}' Name={1}", job.Id, data.Name); } }