Click here to Skip to main content
15,893,161 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.5K   1.8K   93  
Generic methods enable typesafe Threading
Imports System.Text
Imports System.Runtime.Serialization
Imports System.Runtime.CompilerServices

Namespace System
   ''' <summary>
   ''' this Exception is not meant to be handled. Only for logging and debugging-purposes
   ''' </summary>
   <Serializable()> _
   Public Class BugException
      Inherits Exception
      Public Sub New(ByVal message As String)
         MyBase.New(message)
      End Sub
      Protected Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)
         MyBase.New(info, context)
      End Sub
      Public Sub New(ByVal message As String, ByVal innerException As Exception)
         MyBase.New(message, innerException)
      End Sub
   End Class

   Public Module BugExceptionX
      ' these extensions automatically add type-informations to the messages. Furthermore they concat
      '°lists of anything to the message
      <Extension()> _
      Public Function BugException(Of T As Class)( _
            ByVal sender As T, ByVal ParamArray messages As Object()) As BugException
         Return New BugException(String.Concat(sender.ToString(), vbLf, String.Concat(messages)))
      End Function
      <Extension()> _
      Public Function BugException(Of T As Class)(ByVal sender As T, ByVal innerEx As Exception, _
            ByVal ParamArray messages As Object()) As BugException
         Return New BugException(String.Concat( _
            sender.ToString(), vbLf, String.Concat(messages)), innerEx)
      End Function
   End Module
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