private static void StartBackgroundService() { // Register Periodic Tasks BackgroundAggregatorService.Add(() => new PeriodicService()); // Start the background service BackgroundAggregatorService.StopBackgroundService(); // Fix for error if already running. UWP Cannot create a file when that file already exists. BackgroundAggregatorService.StartBackgroundService(); }
protected override void OnSleep() { BackgroundAggregatorService.StopBackgroundService(); // Handle when your app sleeps }
public static async Task Connect(String chaveServicos, String codMotorista) { // _timer = new Timer(OnTickAsync, null, 2000, 1); if (_ws != null && _ws.State == WebSocketState.Open) { return; } //Verifico se servidor está disponível var client = new HttpClient { Timeout = TimeSpan.FromMilliseconds(8000), BaseAddress = new Uri("http://" + ViewModelBase.GetUrlBase() + "/motorapido/wes/") }; client.DefaultRequestHeaders.Add("Authentication", chaveServicos); try { var response = await client.GetAsync("motorista/ping"); Tuple <String, String> tupla = new Tuple <string, string>("Authentication", chaveServicos); List <Tuple <String, String> > lista = new List <Tuple <String, String> >(); lista.Add(tupla); tupla = new Tuple <string, string>("CodMotorista", codMotorista); lista.Add(tupla); IEnumerable <Tuple <String, String> > en = lista; var socketOptions = new PureWebSocketOptions() { DebugMode = true, SendDelay = 100, IgnoreCertErrors = true, MyReconnectStrategy = new ReconnectStrategy(2000, 4000, 20), Headers = en }; _ws = new PureWebSocket("ws://" + ViewModelBase.GetUrlBase() + "/motorapido/socket", socketOptions); _ws.OnStateChanged += Ws_OnStateChanged; _ws.OnMessage += Ws_OnMessage; _ws.OnClosed += Ws_OnClosed; _ws.OnSendFailed += Ws_OnSendFailed; var res = await _ws.ConnectAsync(); Console.ReadLine(); CrossSettings.Current.Remove("ServidorFora"); BackgroundAggregatorService.StopBackgroundService(); } catch (Exception e) { Crashes.TrackError(e); if (!CrossSettings.Current.Contains("ServidorFora")) { CrossSettings.Current.Set("ServidorFora", true); MessagingCenter.Send(new MensagemRespostaSocket() { msg = "Servidor indisponível!" }, "ErroPosicaoArea"); BackgroundAggregatorService.Add(() => new ChecagemServidorDisponivel()); BackgroundAggregatorService.StartBackgroundService(); } } }
protected override void OnSleep() { BackgroundAggregatorService.StopBackgroundService(); }
protected override void OnStart() { BackgroundAggregatorService.StopBackgroundService(); BackgroundAggregatorService.Add(() => new BackgroundTaskJob(10)); //Task run every 10s BackgroundAggregatorService.StartBackgroundService(); }