Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using Plugin.LocalNotifications;
- using Xamarin.Forms;
- namespace DccClassCancelations
- {
- public partial class App : Application
- {
- int count = 0;
- public App ()
- {
- InitializeComponent();
- MainPage = new DccClassCancelations.MainPageCS();
- Xamarin.Forms.DependencyService.Register<IRunInBackground>();
- }
- protected override void OnStart ()
- {
- // Handle when your app starts
- }
- protected override void OnSleep()
- {
- Taskit();
- }
- protected override void OnResume ()
- {
- CrossLocalNotifications.Current.Show("title", "body"+ count.ToString());
- }
- async void Taskit(){
- var deviceInfoServic = DependencyService.Get<IRunInBackground>();
- await deviceInfoServic.RunCodeInBackgroundMode(async () =>
- {
- sleeptimer();
- });
- }
- void sleeptimer()
- {
- if (count < 15)
- {
- Device.StartTimer(TimeSpan.FromSeconds(3), () =>
- {
- Task.Factory.StartNew(() =>
- {
- // Do the actual request and wait for it to finish.
- SendNotification100();
- // Switch back to the UI thread to update the UI
- Device.BeginInvokeOnMainThread(() =>
- {
- // Update the UI
- // ...
- // Now repeat by scheduling a new request
- sleeptimer();
- });
- });
- // Don't repeat the timer (we will start a new timer when the request is finished)
- return false;
- });
- }
- }
- void SendNotification100(){
- CrossLocalNotifications.Current.Show("title", "Text" + count.ToString());
- count++;
- }
- }
- }
Add Comment
Please, Sign In to add comment