Hello,
I cannot use the timer with asynchronous.
when i start the timer all the phone is blocked.
I would like to use the msdn tutorial:
https://learn.microsoft.com/fr-fr/dotnet/csharp/programming-guide/concepts/async/
or
https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/
But I do not happen I only have text underlined in red.
here is my code (PageAccueil.xaml)
public Info_Boutique infoBoutique = App.InfoBoutique;
private static Timer aTimer;
public void SetTimer()
{
// Créez une minuterie avec un intervalle de deux secondes = 2000.
aTimer = new Timer(2000);
// Connectez l'événement.
aTimer.Elapsed += ModifBandeauDate;
aTimer.AutoReset = true;
aTimer.Enabled = true;
aTimer.Start();
}
private void ModifBandeauDate(Object source, ElapsedEventArgs e)
{
NumSemaine.Text = infoBoutique.Semaine_Jeu.ToString();
HeureJour.Text = infoBoutique.Heure_Jeu.ToString() + "h";
switch (infoBoutique.Jour_Jeu)
{
case 1:
JoursSemaine.Text = "lundi";
break;
case 2:
JoursSemaine.Text = "mardi";
break;
. . .
case 7:
JoursSemaine.Text = "dimanche";
break;
}
}
public AccueilPage()
{
InitializeComponent();
infoBoutique.SetTimer();
SetTimer();
}
here is my code (InfoBoutique.cs)
public int Heure_Jeu { get; set; } = 8;
public int Jour_Jeu { get; set; } = 1;
public int Semaine_Jeu { get; set; } = 1;
private static Timer aTimer;
public void SetTimer()
{
// Créez une minuterie avec un intervalle de deux secondes = 2000.
aTimer = new Timer(2000);
// Connectez l'événement Elapsed pour la minuterie.
aTimer.Elapsed += OnTimedEvent;
aTimer.AutoReset = true;
aTimer.Enabled = true;
aTimer.Start();
}
public void OnTimedEvent(Object source, ElapsedEventArgs e)
{
Heure_Jeu += 1;
if (Heure_Jeu == 24)
{
Heure_Jeu = 0;
Jour_Jeu += 1;
}
if (Jour_Jeu == 8)
{
Jour_Jeu = 1;
Semaine_Jeu += 1;
}
}
I can modify the hour + the day by clicking on a button.
But I can't change automatically with the timer, the app freezes.
I think I should use Task or async or await, but I can't use these tools.
the code of the "infoBoutique" class works well.
Hope my translation is ok ;)
Thank you for your help
Manu