Serialization of classes that inherit from abstract classes

Though I’d still love for it to work with the default BackgroundJob.Enqueue, it does appear I found a more verbose work-around.

        var entityId = Guid.NewGuid();
        var abstractExample = new AbstractExample();

        var type = abstractExample.GetType();
        var method = type.GetMethod("Execute");
        var job = new Job(type, method, new[] { entityId.ToString() });

        var client = new BackgroundJobClient();
        client.Create(job, new EnqueuedState());

If you were to want a recurring job, rather than a one-time instantly executing one, you’d use RecurringJobManager.AddOrUpdate instead of BackgroundJobClient.Create.

2 Likes