All the service calls in my application are implemented as tasks.When ever a task is faulted ,I need to present the user with a dialog box to retry the last operation failed
When at the high level, I find it helps to make a function signature from what you have and what you want.
You have:
Func). We'll use the function because tasks themselves are not retryable in general.Func)You want:
So you'll have a function like:
Task Retry(Func action, Func shouldRetry);
Extending the practice inside the function, tasks pretty much have 2 operations to do with them, read their state and ContinueWith. To make your own tasks, TaskCompletionSource is a good starting point. A first try might look something like:
//error checking
var result = new TaskCompletionSource
The obvious problem here is that only 1 retry will ever happen. To get around that, you need to make a way for the function to call itself. The usual way to do this with lambdas is something like this:
//error checking
var result = new TaskCompletionSource