We are leaving Russia. We are against aggression and war with Ukraine. It is a tragedy for our nations, it is a nightmare

Getting return value

I am new to using Hangfire and using it with a .NET Core 5 API.

The API calls a service layer, which contains my implementation. Due to a limitation with a priduct I am using, the service layer has to invoke a Powershell cmdlet on the server.

I have added Hangfire to my code and have a call like below:

        var jobId = BackgroundJob.Enqueue(() => _service.GetVmStats(vmName, hostName));

This returns Task.

How can I return the actual return value?

That would be part of the job. Pseudo code:

public class Do
    private readonly IYourService _service;
    public Do(IYourService service)
        _service = service;

    public async Task Something(string vmName, string hostName)
        var result = await _service.GetVmStats(vmName, hostName);
        // Do something with result.

Use as:

var jobId = BackgroundJob.Enqueue<Do>(x => x.Something(vmName, hostName));