error handling - VB.NET How do i use ApplicationEvents to catch an exception within a thread? -


i have piece of code in applicationevents.vb supposed handle exceptions:

namespace  ' following events available myapplication: '  ' startup: raised when application starts, before startup form created. ' shutdown: raised after application forms closed.  event not raised if application terminates abnormally. ' unhandledexception: raised if application encounters unhandled exception. ' startupnextinstance: raised when launching single-instance application , application active.  ' networkavailabilitychanged: raised when network connection connected or disconnected. partial friend class myapplication      private delegate sub safeapplicationthreadexception(byval sender object, byval e threading.threadexceptioneventargs)      private sub showdebugoutput(byval ex exception)          dim frmd new frmdebug()         frmd.rtferror.appendtext(ex.tostring())         frmd.showdialog()          environment.exit(0)      end sub      private sub myapplication_startup(byval sender object, byval e microsoft.visualbasic.applicationservices.startupeventargs) handles me.startup          system.windows.forms.application.setunhandledexceptionmode(unhandledexceptionmode.automatic)          addhandler system.windows.forms.application.threadexception, addressof app_threadexception           addhandler appdomain.currentdomain.unhandledexception, addressof appdomain_unhandledexception     end sub      private sub app_threadexception(byval sender object, byval e threading.threadexceptioneventargs)           if mainform.invokerequired              mainform.invoke(new safeapplicationthreadexception(addressof app_threadexception), new object() {sender, e})         else             showdebugoutput(e.exception)         end if      end sub      private sub appdomain_unhandledexception(byval sender object, byval e unhandledexceptioneventargs)          showdebugoutput(directcast(e.exceptionobject, exception))      end sub      private sub myapplication_unhandledexception(sender object, e microsoft.visualbasic.applicationservices.unhandledexceptioneventargs) handles me.unhandledexception          showdebugoutput(e.exception)      end sub  end class   end namespace 

however, have found not catch exceptions within, example, bgworker_dowork sub.

it will, however, catch exceptions on same bgworker_runworkercompleted sub.

is there way me catch exceptions within thread, without using try-catch?


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -