title: UWP Navigation page timer
body: <p>I have a problem with the navigation of my pages, when I change page and I come back on my MainPage my timer <code>NiveauTimer</code> didn't works (I have nothings appears in my TextBox) but the timer <code>DispatcherTimer</code> works well. </p>
  
  <pre><code>namespace BassinExpertV1
  {
      public sealed partial class MainPage : Page
      {
          PCF8591 ADConverter;
          DispatcherTimer dispatcherTimer;
          DispatcherTimer NiveauTimer;
  
  
          public MainPage()
          {
  
  
              //Create Timer Date
              dispatcherTimer = new DispatcherTimer();
              dispatcherTimer.Tick += DispatcherTimer_Tick;
              dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
  
              //Create Timer water level
              NiveauTimer = new DispatcherTimer();
              NiveauTimer.Tick += NiveauTimer_Tick;
              NiveauTimer.Interval = new TimeSpan(0, 0, 1);
  
  
              this.InitializeComponent();
  
  
          }
  
          private void Page_Loaded(object sender, RoutedEventArgs e)
          {
  
              dispatcherTimer.Start();    //Timer Date
              NiveauTimer.Start();       //Timer water level
          }
  
  
  
  
          //----------------------------------------------------------------------------
          //                            Timer Date
          //----------------------------------------------------------------------------
          private void DispatcherTimer_Tick(object sender, object e)
          {
              DateHeure.Text = DateTime.Now.ToString();
          }
  
  
  
          //----------------------------------------------------------------------------
          //                            Timer WaterLevel
          //----------------------------------------------------------------------------
          private async void NiveauTimer_Tick(object sender, object e)
          {
              RecupNiveauAsync();
              await System.Threading.Tasks.Task.Delay(2000); //wait for 2 seconds (= 2000ms)
  
              try
              {
  
                  double value = ADConverter.ReadI2CAnalog_AsDouble(PCF8591_AnalogPin.A0) *5 + 95; // Conversion du la valeur du potentiomètre
                  value = Math.Round(value, 2, MidpointRounding.AwayFromZero); //Arrondir la valeur 
                  TextBoxNiveau.Text = Convert.ToString(value) + " %"; // Afficher dans la Textbox la valeur du potentiomètre en %
              }
              catch
              {
                  MessageDialog msg = new MessageDialog("Probleme");
                  await msg.ShowAsync();
              }
  
  
          }
          //----------------------------------------------------------------------------
          //                            Water Level conversion        //----------------------------------------------------------------------------
          private async System.Threading.Tasks.Task RecupNiveauAsync()
          {
              ADConverter = await PCF8591.Create();
  
          }
  
  
          //----------------------------------------------------------------------------
          //                            Bouton automatique
          //----------------------------------------------------------------------------
          private void Automatique_Click(object sender, RoutedEventArgs e)
          {
              this.Frame.Navigate(typeof(Automatique), null); //navigation vers la page automatique
          }
  
  
          //----------------------------------------------------------------------------
          //                            Bouton manuel
          //----------------------------------------------------------------------------
          private void Button_Click(object sender, RoutedEventArgs e)
          {
              this.Frame.Navigate(typeof(Manuel)); //navigation vers la page manuel
          }
  
  
  
          private void TextBlock_SelectionChanged(object sender, RoutedEventArgs e)
          {
  
          }
  
          private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
          {
  
          }
      }
  }
  </code></pre>