public async Task Start() { _cts = new CancellationTokenSource(); _taskId = UIApplication.SharedApplication.BeginBackgroundTask("SyncUnsentChangesTask", OnExpiration); try { var task = new SyncUnsentChangesTask(); await task.RunSyncUnsentChanges(_cts.Token); } catch (OperationCanceledException) { } UIApplication.SharedApplication.EndBackgroundTask(_taskId); }
public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId) { _cts = new CancellationTokenSource(); Task.Run(() => { try { var task = new SyncUnsentChangesTask(); task.RunSyncUnsentChanges(_cts.Token).Wait(); } catch (AggregateException ae) { foreach (var e in ae.InnerExceptions) { if (e is Android.OS.OperationCanceledException) { } } } }, _cts.Token); return(StartCommandResult.Sticky); }