private void BeginInvokeExample() { while (true) { Thread.Sleep(5000); DispatcherOperation op = Dispatcher.BeginInvoke((Action)(() => { var toRemove = new List <Call>(); foreach (var activeCall in ActiveCall) { if (activeCall.CallStart.AddSeconds(activeCall.DurationInSec) <= DateTime.Now) { LogConsole.Items.Add(consoleService.EndCall(activeCall.AgentName, activeCall.DurationInSec)); agentService.AgentDismissal(activeCall.AgentId); toRemove.Add(activeCall); } } foreach (var tr in toRemove) { ActiveCall.Remove(tr); } var call = Calls.Peek(); if (call != null) { var agent = agentService.GetFreeAgent(); if (agent != null) { Calls.Dequeue(); call.AgentName = agent.Name; call.AgentId = agent.Id; call.CallStart = DateTime.Now; ActiveCall.Add(call); LogConsole.Items.Add(consoleService.StartCall(call.AgentName)); } } })); } }