Hi, I have an array with 3 elements for example:
string[] message = {"how","are","you"};
For each of the element, I will assign a timer event with different duration. For example, "how" will display for one minute, "are" with 30 seconds and "you" with 2 minutes. I have successfully added timer for only one element which is "you" as I am using for loop to iterate over each of them but realizing this is not the correct method as the previous two elements' duration will get overwritten with the last duration which is 2 minutes.
Besides, if any of the timer ends, for example "are" will end first as it only has 30 seconds of duration, then system will fire the other 2 elements to my users which are "how" and "you" respectively and again only "you" after "how" is expired.
I am clueless on how should I proceed with my functionality. Below are my current codes:
public string NotifyAllClients(string application, string region, string[] message)
{
if (message.Count() > 0)
{
CountDownTimer(message);
Clients.Group(application).NotifyAllClients(region, message);
}
return "Success!!";
}
public void CountDownTimer(string[] messageWithDuration)
{
foreach (string msg in messageWithDuration)
{
notificationList.ModelList.Add(new NotificationModel()
{
Message = msg,
DisplayFlag = true
});
counterTimerValue = 120;
displayTimer.Interval = 1000;
displayTimer.Elapsed += new ElapsedEventHandler(timerTick);
displayTimer.Enabled = true;
displayTimer.Start();
}
}
private void timerTick(Object source, EventArgs e)
{
counterTimerValue--;
if (counterTimerValue == 0)
{
displayTimer.Stop();
try
{
List<string> list = new List<string>();
notificationList.ModelList[0].DisplayFlag = false;
notificationList.ModelList = notificationList.ModelList.Where(x => x.DisplayFlag == true).ToList();
foreach(NotificationModel model in notificationList.ModelList)
{
list.Add(model.Message);
}
messageContent = list.ToArray();
Clients.Group(application).NotifyAllClients(region, message);
}
catch (Exception)
{
}
}
}
I have comment out some codes to simplify the question posted.
What I have tried:
1. Search online for ideas/brainstorming but no avail.