Perform Control Transfer With Retry
public static Task<T> PerformControlTransferWithRetry<T>( | |
this IUsbDevice usbDevice, | |
Func<IUsbDevice, Task<T>> func, | |
int retryCount = 3, | |
int sleepDurationMilliseconds = 250) | |
{ | |
var retryPolicy = Policy | |
.Handle<ApiException>() | |
.Or<ControlTransferException>() | |
.WaitAndRetryAsync( | |
retryCount, | |
i => TimeSpan.FromMilliseconds(sleepDurationMilliseconds), | |
onRetryAsync: (e, t) => usbDevice.ClearStatusAsync() | |
); | |
return retryPolicy.ExecuteAsync(() => func(usbDevice)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment