.RetryForeverAsync(...) . , , onRetryAsync:. :
.RetryForeverAsync(onRetryAsync: async (e,i) => await RefreshAuthorization());
, : , onRetry:, , onRetry ( void), async .
, async-delegate-assign-to-sync-param async void; / . async void , .
System.AggregateException: A Task exception(s) were not observed myTask ( q ).
:
Re:
, RetryForeverAsync .
( / ), , , Func<Task<R>> , - Func<Task<R>> . . : retry.
- (, ) , , RefreshAuthorization() , , .
public class WebExceptionCatcher<T, R> where T : Task<R>
{
public async Task<R> runTask(Func<T> t)
{
int j = 0;
Policy p = Policy.Handle<WebException>()
.Or<MobileServiceInvalidOperationException>()
.Or<HttpRequestException>()
.RetryForeverAsync(onRetryAsync: async (e,i) => await RefreshAuthorization());
return await p.ExecuteAsync<R>( async () =>
{
j++;
if ((j % 5) == 0) Device.BeginInvokeOnMainThread(async () =>
{
await DisplayAlert("Making retry "+ i, "whatever", "Ok");
});
await myTask;
});
}
}
RefreshAuthorization()) , Connection Lost , Making retry 5.
RefreshAuthorization()) , ( ) , Connection Lost. , Connection Lost , Making retry 5, Making retry 10 ( .., , ), Connection Lost.
(, ) , , Polly . myTask, myTask - .
UPDATE : " runTask():"
: , , , .
:
Task<TodoItem> t = App.MobileService.GetTable<TodoItem>().LookupAsync(id);
TodoItem item = await catcher.runTask(() => t); // Or same effect: TodoItem item = await catcher.runTask(async () => await t);
- App.MobileService.GetTable<TodoItem>().LookupAsync(id) , Polly ( , while for ).
A Task "re-runnable": Task . :
Task<TodoItem> t = App.MobileService.GetTable<TodoItem>().LookupAsync(id);
LookupAsync(id) t a Task, , LookupAsync ( ) . lambda () => t, Task, . ( t , , func , - LookupAsync(id).). , , , , , Polly, await -ing a Task, , .
Task , , :
int i = 0;
int j = i++;
Func<int> myFunc = () => j;
for (k=0; k<5; k++) Console.Write(myFunc());
, 12345, (, , j ) 11111.
, :
TodoItem item = await catcher.runTask(() => App.MobileService.GetTable<TodoItem>().LookupAsync(id));
lambda .LookupAsync(id) , Task<ToDoItem>, .