Hangfire Batch does not seem atomic

I’m running the following test code and what I would expect to see is that if iterations > 5 none of my enqueued jobs are ever run since I throw and exception in the middle of the loop. However what I’m seeing is that jobs 0-4 are in fact logging out to the console. I’ve tried this with InMemory, SQLServier, and Redis providers. Am I doing something wrong?

static void Main(string[] args)

        using (var server = new BackgroundJobServer())
            Console.WriteLine("Hangfire Server started.");
            Console.WriteLine("How many jobs?");
            var iterations = Int32.Parse(Console.ReadLine());


            Console.WriteLine("Press any key to exit");


static void EnqueueJobs(int iterations)
        var sw = new Stopwatch();
        var rnd = new Random();
            BatchJob.StartNew(x =>
                for (var i = 0; i < iterations; i++)
                    if (i == 5) throw new Exception("Test");
                    BackgroundJob.Enqueue(() => Console.Write("\rFire-and-forget {0} - {1}            ", i, sw.Elapsed));
        catch (Exception e){ }
        Console.WriteLine("Enqueued in "+  sw.Elapsed);

Have never worked with batches, but shouldn’t it be x.Enqueue(() => ...) instead?

That was it… Boy do I feel dumb. Thanks for being my extra set of eyes :slight_smile: