public MainWindow() { InitializeComponent(); _trayIcon = new TrayIcon(this); Top = 0; Left = 100; Topmost = ConfigManager.Config.StayOnTop; Task.Factory.StartNew(() => { while (true) { try { int count = ElmahErrorItem.PullItems(); if (count > 0) { // recount incoming errors NewIncomingErrorCount += count; // bind error list to list box listBox1.Dispatcher.Invoke( new Action(() => { listBox1.DataContext = ElmahErrorItem.LatestItems; })); } } catch { } // wait for next pull Thread.Sleep(ConfigManager.Config.Interval * 1000); } }, TaskCreationOptions.LongRunning); }