增加后台长期任务OnException处理异常
This commit is contained in:
parent
f576b9ff34
commit
0bcaef1383
|
@ -30,6 +30,10 @@ namespace Falcon.SugarApi.BackTask
|
||||||
/// 完成一次执行
|
/// 完成一次执行
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected virtual void OnCompleted(BackgroundLongTask t) { }
|
protected virtual void OnCompleted(BackgroundLongTask t) { }
|
||||||
|
/// <summary>
|
||||||
|
/// 执行中发生未处理异常
|
||||||
|
/// </summary>
|
||||||
|
protected virtual void OnException(BackgroundLongTask t, Exception ex) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 用于定期执行任务的委托
|
/// 用于定期执行任务的委托
|
||||||
|
@ -46,8 +50,15 @@ namespace Falcon.SugarApi.BackTask
|
||||||
OnStart(this);
|
OnStart(this);
|
||||||
while (!TokenSource.Token.IsCancellationRequested) {
|
while (!TokenSource.Token.IsCancellationRequested) {
|
||||||
await Task.Delay(TimeSpan.FromSeconds(RunTimespan))
|
await Task.Delay(TimeSpan.FromSeconds(RunTimespan))
|
||||||
.ContinueWith(_ => { RunAsync().Wait(); })
|
.ContinueWith(async _ => {
|
||||||
.ContinueWith(_ => OnCompleted(this));
|
try {
|
||||||
|
await RunAsync();
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
OnException(this, ex);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.ContinueWith(t => { OnCompleted(this); });
|
||||||
}
|
}
|
||||||
OnStop(this);
|
OnStop(this);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user