直到Hangfire支持async / await,将作业创建方法的调用封装在火中并忘记HostingEnvironment.QueueBackgroundWorkItem或StephenCleary/AspNetBackgroundTasks等API是个好主意吗?
的示例:
HostingEnvironment.QueueBackgroundWorkItem((cancelationToken) => BackgroundJob.Enqueue(() => SomeClass.DoWork()));
或
BackgroundTaskManager.Run(() =>
{
BackgroundJob.Enqueue(() => SomeClass.DoWork());
});