如题
https://github.com/sergezhigunov/Hangfire.EntityFrameworkCore/issues/32
public class Worker : IBackgroundProcess
{
public void Execute(BackgroundProcessContext context)
{
using (var fetchedJob = connection.FetchNextJob(_queues.ToArray(), context.StoppingToken))
{
...
fetchedJob.RemoveFromQueue();// 它会设置EFCoreFetchedJob._completed=true,进而导致后续的_timer.Dispose()未执行
...
}
}
}
internal sealed class EFCoreFetchedJob : IFetchedJob
{
private bool _completed;
public void RemoveFromQueue()
{
lock (_lock)
{
_storage.UseContext(context =>
{
context.Remove(_queuedJob);
try
{
context.SaveChanges();
}
catch (DbUpdateConcurrencyException)
{
// Someone else already has removed item, database wins
}
});
_completed = true;//这里在Dispose前就执行了
}
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool disposing)
{
if (!_disposed)
{
if (disposing && !_completed)//因为_completed=true,所以_timer.Dispose()不执行
{
_timer.Dispose();
Requeue();
}
_disposed = true;
}
}
}
标签:Dispose,completed,hangfire,System,public,Threading,context,true,void
From: https://www.cnblogs.com/pains/p/18634141