Exemple #1
0
        public async Task Start()
        {
            _cts = new CancellationTokenSource();

            _taskId = UIApplication.SharedApplication.BeginBackgroundTask("SyncScheduleStateTask", OnExpiration);

            try
            {
                var task = new SyncAttendanceTask();
                await task.RunSyncAttendance(_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 SyncAttendanceTask();
                    task.RunSyncAttendance(_cts.Token).Wait();
                }
                catch (AggregateException ae)
                {
                    foreach (var e in ae.InnerExceptions)
                    {
                        if (e is Android.OS.OperationCanceledException)
                        {
                        }
                    }
                }
            }, _cts.Token);

            return(StartCommandResult.Sticky);
        }