Example #1
0
        public override StartCommandResult OnStartCommand(Intent intent, [GeneratedEnum] StartCommandFlags flags, int startId)
        {
            cancellationTokenSource = new CancellationTokenSource();

            CreateNotification();

            Task.Run(() =>
            {
                try
                {
                    //var task = new LongRunningTask(cancellationTokenSource.Token);
                    var task = new WebSocketProcesser();
                    task.StartTask().Wait();
                }

                catch (System.OperationCanceledException)
                {}
                finally
                {
                    if (cancellationTokenSource.IsCancellationRequested)
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            MessagingCenter.Send <AndroidService>(this, Events.Events.CancelledTask);
                        });
                    }
                }
            }, cancellationTokenSource.Token);

            return(StartCommandResult.Sticky);
        }