public void Close() { LongWaitMessage lwmC = null; if (_IsInAnotherUIThread) { lwmC = lwm_A; } else { if (lwm == null) { Thread.Sleep(1000); } lwmC = lwm; } if (lwmC != null) { lwmC.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { if (lwmC != null) { lwmC.Close(); lwmC = null; } }) ); } //close.Set(); isOpen = false; }
public void Show() { if (_IsInAnotherUIThread) { isOpen = true; Dispatcher dispatcher = System.Windows.Application.Current.MainWindow.Dispatcher; newWindowThread = new Thread(new ThreadStart(() => { latch.Set(); lwm_A = new LongWaitMessage(_Message, _IsInAnotherUIThread); lwm_A.DataContext = this; while (isOpen) { //dispatcher.BeginInvoke(new Action(() => System.Windows.Application.Current.MainWindow.Refresh())); lwm_A.Refresh(); Thread.Sleep(500); } //EventWaitHandle.WaitAny(new WaitHandle[] { close }); lwm_A.Close(); })); newWindowThread.CurrentUICulture = System.Globalization.CultureInfo.CurrentUICulture; newWindowThread.SetApartmentState(ApartmentState.STA); newWindowThread.IsBackground = true; newWindowThread.Start(); EventWaitHandle.WaitAny(new WaitHandle[] { latch });//wait thread start } else { lwm = new LongWaitMessage(_Message, _IsInAnotherUIThread); lwm.DataContext = this; lwm.ShowDialog(); } }