Esempio n. 1
0
        static void Main(string[] args)
        {
            GlobalConfiguration.Configuration
            .UseSqlServerStorage("Hangfire")
            .UseConsole();

            var now     = DateTime.UtcNow;
            var fooArgs = new FooArgs()
            {
                MyProperty1 = 1,
                MyProperty2 = now,
                MyProperty3 = new List <Bar>()
                {
                    new Bar()
                    {
                        MyProperty1 = 1, MyProperty2 = "1"
                    }
                }
            };

            for (int i = 0; i < 5; i++)
            {
                BackgroundJob.Enqueue <Producer>(x => x.Produces1(null, $"SomeKey"));
                BackgroundJob.Enqueue <Producer>(x => x.Produces2(fooArgs, null));
            }

            System.Console.WriteLine("Enqueue completed");
            System.Console.ReadKey();
        }
Esempio n. 2
0
        public async Task Produces2(FooArgs args, PerformContext context)
        {
            context.WriteLine("Doing something that requires a lock...");

            // Emulates semi-long running operation
            await Task.Delay(TimeSpan.FromSeconds(3));

            context.WriteLine("Long running task completed");
        }