Background Worker Wrapper (oldie but goodie)

Ran into a need to run a long running process in a Windows Application

Figured writing a wrapper class made calling it much easier

public class BackgroundWorkerWrapper


BackgroundWorker _worker;

public Action RunAction{get; set;}

public Action PostAction{get; set;}

public BackgroundWorkerWrapper(Action runAction = null, Action postAction = null)


RunAction = runAction;

PostAction = postAction;

_worker = new BackgroundWorker();

_worker.WorkerReportsProgress = true;

_worker.DoWork += _worker_DoWork;

_worker.RunWorkerCompleted += _worker_RunWorkerCompleted;



public void Run()




void _worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)




void _worker_DoWork(object sender, DoWorkEventArgs e)








Share on Facebook

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>