I currently have four if statements in my code to change certain displays. On the if statement for InQueueInRing > 10 I would like it to cycle every .5 seconds between the Red, Yellow, and Green images until the condition is no longer true. I'm not sure where to start with cycling images. Do I just list the image source multiple times with a Thread.Sleep(1000) in between them?
I tried to use Loading new image each second but i can't convert type system.threading.timer to system.windows.media.imagesource. updated code below.
Below are my if statements
if (e.CmsData.Skill.AgentsAvailable > 0)
{
Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() =>
{
callsWaitingData.Text = e.CmsData.Skill.AgentsAvailable.ToString();
callsWaitingData.Foreground = new SolidColorBrush(Colors.Green);
callsWaitingText.Text = "Available";
callimgae.Source = new BitmapImage(new Uri("pack://application:,,,/ScoreBoardClientTest;component/images/circle_green.png", UriKind.Absolute));
}));
}
else if (e.CmsData.Skill.InQueueInRing > 10)
{
Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() =>
{
callsWaitingData.Text = e.CmsData.Skill.InQueueInRing.ToString();
callsWaitingData.Foreground = new SolidColorBrush(Colors.Red);
callsWaitingText.Text = "Waiting";
timer = new system.threading.timer(OnTImerEllapsed, new object(), 0, 2000);
}));
}
else if (e.CmsData.Skill.InQueueInRing > 0)
{
Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() =>
{
callsWaitingData.Text = e.CmsData.Skill.InQueueInRing.ToString();
callsWaitingData.Foreground = new SolidColorBrush(Colors.Red);
callsWaitingText.Text = "Waiting";
callimgae.Source = new BitmapImage(new Uri("pack://application:,,,/ScoreBoardClientTest;component/images/circle_red.png", UriKind.Absolute));
}));
}
else if (e.CmsData.Skill.AgentsAvailable == 0)
{
Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() =>
{
callsWaitingData.Text = e.CmsData.Skill.AgentsAvailable.ToString();
callsWaitingData.Foreground = new SolidColorBrush(Colors.Yellow);
callsWaitingText.Text = "Available";
callimgae.Source = new BitmapImage(new Uri("pack://application:,,,/ScoreBoardClientTest;component/images/circle_yellow.png", UriKind.Absolute));
}));
}
private void OnTimerEllapsed(object state)
{
if (!this.Dispatcher.CheckAccess())
{
this.Dispatcher.Invoke(new Action(LoadImages));
}
}
private void LoadImages()
{
string stringUri = switcher ? @"pack://application:,,,/ScoreBoardClientTest;component/images/circle_red.png" :
@"pack://application:,,,/ScoreBoardClientTest;component/images/circle_yellow.png";
// @"pack://application:,,,/ScoreBoardClientTest;component/images/circle_green.png";
this.callimgae.Source = new BitmapImage(new Uri(stringUri));
switcher = !switcher;
}