wpf - Dispatcher.CurrentDispatcher.BeginInvokeShutdown closes the main thread c# -
i opening wpf ui in separate thread using
helperthread = new thread(() => { //showhelpindialog(e.url, -1, -1, -1, -1, e.helpcontext); //system.windows.threading.dispatcher.run(); dispatcher.invoke(new action(() => showhelpindialog(e.url, -1, -1, -1, -1, e.helpcontext))); }); helperthread.setapartmentstate(apartmentstate.sta); helperthread.isbackground = true; helperthread.start();
during dialog close event, calling
dispatcher.currentdispatcher.begininvokeshutdown(dispatcherpriority.background);
which causing main thread/application close, don't want.
i don't want parent application close.
please observe following example on how open new window
thread:
private void newwindowhandler(object sender, routedeventargs e) { thread newwindowthread = new thread(new threadstart(threadstartingpoint)); newwindowthread.setapartmentstate(apartmentstate.sta); newwindowthread.isbackground = true; newwindowthread.start(); } private void threadstartingpoint() { window1 tempwindow = new window1(); tempwindow.show(); system.windows.threading.dispatcher.run(); }
from multiple windows, multiple threads section of
threading model
page @ msdn.
update >>>
this code 100% tested , open new window
in new thread. if don't want shut down other window
, don't call begininvokeshutdown
method shut window
down. you're calling on dispatcher.currentdispatcher
running on main thread (where mainwindow.xaml
running).
Comments
Post a Comment