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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -