c# - Nothing happening when you click second time -
i having terrible when execute same method second time.i not getting wpf screen, don't know why? refer code
testwindow button click method(it windows application project type) , have removed sta thread in
main()
testclass test;
private void button1_click(object sender, eventargs e) { test =testclass.instance; //singleton pattern test.showscreen(); } testclass
public void showscreen() { var thread = new thread(() => { explorer explorer = new explorer(); explorer.show(); explorer.closed += (s, args) => explorer.dispatcher.invokeshutdown(); system.windows.threading.dispatcher.run(); }); thread.setapartmentstate(apartmentstate.sta); thread.start(); } above code working fine when run 1st time. can able view explorer screen. problem when close 1st screen , call once again same method(test.showscreen();) explorer screen not showing
note : have noticed if didn't close 1st window(instance) can able open many explorer screen. using same code. if closed 1st window(instance) , unable open explorer screen , not getting error message.
the issue resolved adding following line in testclass constructors
using sw = system.windows;
private testclass() { if (sw.application.current == null) { new sw.application { shutdownmode = sw.shutdownmode.onexplicitshutdown }; } }
Comments
Post a Comment