Objects instance losing values


#1

Hello

I am new to Hangfire and am hoping that there’s a simple answer to this. I am trying to enqueue a method which is a member of a class. I have tried two different methods. Both ways, the class seems to lose all of its values:

    public void DoSomething()
    {
        BackgroundJob.Enqueue<Person>(x => new Person("Joe", "Bloggs").DoSomething());
    }

and

    public void DoSomething()
    {
        Person person = new Person()
        {
            FirstName = "Joe",
            LastName = "Bloggs"
        };

        BackgroundJob.Enqueue<Person>(x => person.DoSomething());
    }

Is anyone able to point me in the right direction?

Regards

Peter


#2

Try BackgroundJob.Enqueue(()=>person.DoSomething());