c# - Thread.Abort () causing application to kill -
i developing wpf application displays wait dialog users if lengthy work going on. have created wait dialog windows form inherited system.windows.forms.form. when user change settings , apply, display waitdialog , let application validate , save new configurations. display dialog create thread , invoke method in-turn call showdialog() method of waitdialog form. when settings validated , saved, need hide/disapper waitdialog form. so, thread.abort() used abort thread displays waitdialog.
this way, when user clicks on apply button save new configurations, wait dialog displays , hide , message box shown if user made wrong entries. if user clicks on apply button again, application displays unhandled exception messagebox stating "thread being aborted." solve issue, have used following:
1- put thread.abort() statement in try/catch block.
2- used thread.resetabort() statement inside catch block.
3- subscribed different events on application startup:
appdomain.currentdomain.unhandledexception += new unhandledexceptioneventhandler(currentdomain_unhandledexception); appdomain.currentdomain.firstchanceexception += new eventhandler<system.runtime.exceptionservices.firstchanceexceptioneventargs>(currentdomain_firstchanceexception); this.dispatcherunhandledexception += new system.windows.threading.dispatcherunhandledexceptioneventhandler(app_dispatcherunhandledexception); system.windows.forms.application.threadexception += new system.threading.threadexceptioneventhandler(application_threadexception);
still unable eat exception. please suggest way rid of issue. causes weired exception , kill application.
this how have approached it. put call wait dialog in method eg
formwaitdialog _waitdialog=new formwaitdialog(); void showdialog(){ thread t = new thread(()=>{ invoke(new action(()=> { _waitdialog.show(); })); }); t.start(); }
and in click event of validate button call method
then in exit method call _waitdialog.hide();
Comments
Post a Comment