Ejemplo n.º 1
0
        public async Task StartCheckWatchesTimer(string lastRunTime)
        {
            //CrossLocalNotifications.Current.Show("title", lastRunTime);

            DoCheckWatches = true;

            DateTime lastRunTimeDateTime = DateTime.Parse(lastRunTime);
            //lastRunTimeDateTime = lastRunTimeDateTime.AddSeconds(310);
            int delay = Convert.ToInt32(lastRunTimeDateTime.AddSeconds(325).Subtract(DateTime.Now).TotalMilliseconds);


            if (delay > 0)
            {
                await Task.Delay(delay);
            }

            while (DoCheckWatches)
            {
                string notificationString = await Wservice.CheckWatches(Items);

                // Update the UI (because of async/await magic, this is still in the UI thread!)
                if (notificationString != null)
                {
                    CrossLocalNotifications.Current.Show(Translater.ProvideValue("Overbid:"), notificationString);
                }

                if (DoCheckWatches)
                {
                    await Task.Delay(TimeSpan.FromSeconds(310));
                }
            }

            /*Device.StartTimer(TimeSpan.FromSeconds(10), () =>
             * {
             *   Task.Factory.StartNew(async () =>
             *   {
             *       // Do the actual request and wait for it to finish.
             *
             *       if (Wservice.LastUpdateTime != null)
             *           await CheckWatches();
             *       // Switch back to the UI thread to update the UI
             *       Device.BeginInvokeOnMainThread(() =>
             *       {
             *           // Update the UI
             *           // ...
             *           // Now repeat by scheduling a new request
             *           //ScheduleWebRequest();
             *       });
             *   });
             *
             *   // Don't repeat the timer (we will start a new timer when the request is finished)
             *   return false;
             * });*/
        }