I am trying to code a simple background workers class without needing to use the backgroundworke r object on a form. This would allow me to use a background worker in any class without writing much additional code. Is it possible to pass in the name of a sub at runtime instead of hard-coding it? To do this I would replace onDoWork and onProgressChang ed below and use (Byval onWorkSub as SomeKindOfObjec t?, Byval onProgressChang edSub as SomeKindOfObjec t?) instead.
Code:
' Instantiate the worker
Dim worker As New BackgroundWorker ' Initialize the worker
worker.WorkerReportsProgress = True
worker.WorkerSupportsCancellation = True
AddHandler worker.DoWork, New DoWorkEventHandler(AddressOf onDoWork) ' Create delegate handle
AddHandler worker.ProgressChanged, New ProgressChangedEventHandler(AddressOf onProgressChanged) ' Create callback handle
'* start the worker
worker.RunWorkerAsync()
Comment