Click here to Skip to main content
15,892,005 members
Articles / Desktop Programming / Windows Forms

AsyncWorker - A Typesafe BackgroundWorker (and about Threading in General)

Rate me:
Please Sign up or sign in to vote.
4.76/5 (23 votes)
11 Apr 2010CPOL9 min read 58.4K   1.8K   93  
Generic methods enable typesafe Threading
Imports Microsoft.VisualBasic.ApplicationServices
Imports WinFormApp = System.Windows.Forms.Application

Namespace My

   Partial Friend Class MyApplication

      Private Sub App_Startup(ByVal sender As Object, ByVal e As StartupEventArgs) Handles Me.Startup
         AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf SideThread_Exception
         AddHandler WinFormApp.ThreadException, AddressOf MainThread_Exception
      End Sub

      Private Shared Sub MainThread_Exception(ByVal sender As Object, ByVal e As System.Threading.ThreadExceptionEventArgs)
         MessageBox.Show("Log unhandled main-thread-Exception here" & vbLf & e.Exception.ToString())
         WinFormApp.Exit()
      End Sub

      Private Shared Sub SideThread_Exception(ByVal sender As Object, ByVal e As System.UnhandledExceptionEventArgs)
         MessageBox.Show("Log unhandled side-thread-Exception here" & vbLf + e.ExceptionObject.ToString())
         WinFormApp.Exit()
      End Sub

   End Class

End Namespace

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions