Click here to Skip to main content
15,886,362 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace System {
   /// <summary>
   /// this Exception is not meant to be handled. Only for logging and debugging-purposes
   /// </summary>
   [Serializable]
   public class BugException : Exception {
      public BugException(string message) : base(message) { }
      protected BugException(SerializationInfo info, StreamingContext context)
         : base(info, context) { }
      public BugException(string message, Exception innerException)
         : base(message, innerException) { }
   }
   public static class BugExceptionX {
      // these extensions automatically add type-informations to the messages. Furthermore they concat
      //�lists of anything to the message
      public static BugException BugException<T>(
            this T sender, params string[] messages) where T : class {
         return new BugException(string.Concat(sender.ToString(), "\n", string.Concat(messages)));
      }
      public static BugException BugException<T>(
         this T sender, Exception innerEx, params string[] messages) where T : class {
         return new BugException(
            string.Concat(sender.ToString(), "\n", string.Concat(messages)), 
            innerEx);
      }
   }
}

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