Guest User

Untitled

a guest
Mar 29th, 2018
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. using Plugin.LocalNotifications;
  8. using Xamarin.Forms;
  9.  
  10. namespace DccClassCancelations
  11. {
  12.    
  13.     public partial class App : Application
  14.     {
  15.         int count = 0;
  16.      
  17.         public App ()
  18.         {
  19.             InitializeComponent();
  20.  
  21.             MainPage = new DccClassCancelations.MainPageCS();
  22.             Xamarin.Forms.DependencyService.Register<IRunInBackground>();
  23.  
  24.         }
  25.  
  26.         protected override void OnStart ()
  27.         {
  28.             // Handle when your app starts
  29.         }
  30.  
  31.         protected override void OnSleep()
  32.         {
  33.  
  34.             Taskit();
  35.  
  36.                 }
  37.  
  38.        
  39.         protected override void OnResume ()
  40.         {
  41.             CrossLocalNotifications.Current.Show("title", "body"+ count.ToString());
  42.  
  43.          
  44.         }
  45.  
  46.         async void Taskit(){
  47.  
  48.             var deviceInfoServic = DependencyService.Get<IRunInBackground>();
  49.             await deviceInfoServic.RunCodeInBackgroundMode(async () =>
  50.             {
  51.                 sleeptimer();
  52.             });
  53.         }
  54.  
  55.  
  56.         void sleeptimer()
  57.         {
  58.  
  59.             if (count < 15)
  60.             {
  61.  
  62.                 Device.StartTimer(TimeSpan.FromSeconds(3), () =>
  63.                 {
  64.                     Task.Factory.StartNew(() =>
  65.                {
  66.                     // Do the actual request and wait for it to finish.
  67.                     SendNotification100();
  68.                     // Switch back to the UI thread to update the UI
  69.                     Device.BeginInvokeOnMainThread(() =>
  70.                         {
  71.                         // Update the UI
  72.                         // ...
  73.                         // Now repeat by scheduling a new request
  74.  
  75.                         sleeptimer();
  76.                         });
  77.                     });
  78.  
  79.                 // Don't repeat the timer (we will start a new timer when the request is finished)
  80.                 return false;
  81.                 });
  82.             }
  83.         }
  84.  
  85.  
  86.         void SendNotification100(){
  87.  
  88.  
  89.  
  90.                 CrossLocalNotifications.Current.Show("title", "Text" + count.ToString());
  91.             count++;
  92.            
  93.         }
  94.  
  95.  
  96.        
  97.     }
  98. }
Add Comment
Please, Sign In to add comment