如何从 Hangfire 中启动的方法获取返回值?

问题描述 投票:0回答:0

当使用 Hangfire 启动一个方法时,你得到的唯一返回值是 Hangfire 框架提供的 Hangfire 作业的 ID,但我需要该方法的返回值。如何从实际方法中获取返回值?

假设我有以下代码:

public void SomeMethod()
{
    var jobId = BackgroundJob.Enqueue(() => ReturnValue());
}

public bool ReturnValue()
{
    return true;
}

我想在

ReturnValue()
中获取
SomeMethod()
方法的返回值,这可能吗?我该怎么做?
true
值显示在 Hangfire 仪表板中,但我想在代码中使用它。 这样的事情不起作用:

public void SomeMethod()
{
    bool result = false;
    var jobId = BackgroundJob.Enqueue(() => result = ReturnValue());
}

在谷歌搜索这个问题时,我发现其他人也有这个问题。我找到了这些解决方案:

c# .net hangfire
© www.soinside.com 2019 - 2024. All rights reserved.