Hi, I have an array, let say 3 elements in it as below:
string [] message = {how, are, you};
int counterTimerValue = 0;
For each element in the array, I would need to display them for 10 seconds for example. And when it reach the final element, it will go back to the first element and display the first element, second element again and again.
I have used a timer object to control the duration but clueless on how should I assign each element a timer or so.
Below are my current codes:
for(int i = 0; i < message.Length; i++)
{
counterTimerValue = 10;
displayTimer.Interval = 1000;
displayTimer.Tick += new EventHandler(this.displayTimerTick);
displayTimer.Start();
}
private void displayTimerTick(Object source, EventArgs e)
{
counterTimerValue--;
try
{
int index = (messageArray.Length - 1 - (counterTimerValue % messageArray.Length));
txtNotification.Text = messageArray[index];
}
catch (Exception)
{
}
if (counterTimerValue == 0)
{
displayTimer.Stop();
}
}
The above codes will only display the last element "you" because the for loop will finish executing all the elements in the array instead of wait for the timer to finish one element then only go for another element.
Any help would be appreciated. Thank you.
What I have tried:
1. Search online for any ideas/brainstorming but no avail.