如何单独而不是并行处理Hangfire BackgroudJob?

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

我有一个Hangfire BackgroundJob.Enque()方法,其中写入了我所有的业务逻辑。

它一次可以处理一个请求,但是多个请求都一起启动,会产生死锁问题。

我希望请求单独执行;请问我该如何实现?

c# asp.net-web-api background-process hangfire
1个回答
0
投票

[After reading the documentation,看来您的答案是设置'并行度'。

为此,设置进行处理的后台线程的数量...

var options = new BackgroundJobServerOptions { WorkerCount = Environment.ProcessorCount * 5 };
app.UseHangfireServer(options);

...或...

var options = new BackgroundJobServerOptions
{
    // This is the default value
    WorkerCount = Environment.ProcessorCount * 5
};

var server = new BackgroundJobServer(options);

...分别用于Web或Windows。

© www.soinside.com 2019 - 2024. All rights reserved.