The TPLHelper library is awesome. I use it frequently in many apps to handle threading stuff for me.

For instance, you can set it up like so to fire up a task and then handle finish tasks and even an exception in a task. The following example shows calling a method called LoadDictionaryItems on a seperate thread.

Dim ProcessorTask As Task = Task.Factory.StartNew( _ 
                   Sub() 
                        LoadDictionaryItems() 
                   End Sub _ 
                    )
CurrentProgressReporter.RegisterContinuation(ProcessorTask, _ 
              Sub() 
                  FinishResultProcessing() 
              End Sub)
          CurrentProgressReporter.RegisterFaultedHandler(ProcessorTask, _ 
               Sub() 
                  ThreadFaultHandling(ProcessorTask) 
              End Sub)

I had just implemented this code and the ui was crashing with the following error:’System.NullReferenceException’.  After messing with this for a bit, i finally figured out it was crashing because i had not fired up the ProgressReporter instance CurrentProgressReporter.

The working code looks like this:

CurrentProgressReporter = New TPLHelper.ProgressReporter()
Dim ProcessorTask As Task = Task.Factory.StartNew( _ 
                   Sub() 
                       LoadDictionaryItems() 
                   End Sub _ 
                    )
CurrentProgressReporter.RegisterContinuation(ProcessorTask, _ 
               Sub() 
                   FinishResultProcessing() 
               End Sub)
          CurrentProgressReporter.RegisterFaultedHandler(ProcessorTask, _ 
               Sub() 
                   ThreadFaultHandling(ProcessorTask) 
               End Sub)