void ThreadProc() { ClientMsg msg2 = new ClientMsg(); MsgService msgsvc = new MsgService(); try { while (true) { msg2 = msgsvc.GetMessageCS(); // get message out of receive queue - will block if queue is empty if (msg2.body != null) { this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, OnNewMessage, msg2); } } } catch (Exception ex) { MessageBox.Show("A handled exception just occurred: " + ex.Message, "Exception Sample", MessageBoxButton.OK, MessageBoxImage.Warning); } }