-
Notifications
You must be signed in to change notification settings - Fork 2
Retry
ZjzMisaka edited this page Apr 19, 2024
·
3 revisions
After setting WorkOption.RetryOption, if a task throws an exception and fails to execute, it will be retried according to the settings.
You can configure the retry behavior (immediate retry or requeue), set the number of retries, or allow for unlimited retries (properties to stop retrying are provided in both callback and WorkEnded event parameters).
powerPool.QueueWorkItem(() =>
{
throw new Exception();
}, new WorkOption<object>()
{
RetryOption = new RetryOption()
{
RetryBehavior = RetryBehavior.Requeue,
RetryPolicy = RetryPolicy.Limited,
MaxRetryCount = 5,
},
Callback = (res) =>
{
if (res.Status == Status.Failed)
{
if (res.RetryInfo.CurrentRetryCount == 2)
{
res.RetryInfo.StopRetry = true;
}
}
}
});