public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId) { _cts = new CancellationTokenSource(); Task.Run(() => { try { var pendingTaskList = new TaskEnumeratePending(); pendingTaskList.RunEnumeration(_cts.Token).Wait(); } catch (Android.OS.OperationCanceledException) { } finally { if (_cts.IsCancellationRequested) { var message = new CancelledMessage(); Device.BeginInvokeOnMainThread( () => MessagingCenter.Send(message, "CancelledMessage") ); } } }, _cts.Token); return(StartCommandResult.Sticky); }
public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId) { _cts = new CancellationTokenSource(); Task.Run(() => { try { var pendingTaskList = new TaskEnumeratePending(); pendingTaskList.RunEnumeration(_cts.Token).Wait(); } catch (Android.OS.OperationCanceledException) { } finally { if (_cts.IsCancellationRequested) { var message = new CancelledMessage(); Device.BeginInvokeOnMainThread( () => MessagingCenter.Send(message, "CancelledMessage") ); } } }, _cts.Token); return StartCommandResult.Sticky; }