---
title: "A better BackgroundWorker : CancelImmediately and other goodies"
url: "https://osherove.com/blog/2005/11/9/a-better-backgroundworker-cancelimmediately-and-other-goodie.md"
canonical: "https://osherove.com/blog/2005/11/9/a-better-backgroundworker-cancelimmediately-and-other-goodie.html"
published: "2005-11-09T18:14:00"
updated: "2005-11-09T18:14:00"
tags: [".Net 2.0"]
author: "Roy Osherove"
description: "One of the nice new features you get in .NET 2.0 Winforms is the new BackgroundWorker component. It allows safely executing long tasks in a different thread than the GUI, while allowing an easy event-driven interface to…"
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# A better BackgroundWorker : CancelImmediately and other goodies

By Roy Osherove November 9, 2005 In [.Net 2.0](https://osherove.com/blog/category/net-2-0)

**Historical article** · Originally published November 9, 2005; technical details may be outdated.

One of the nice new features you get in .NET 2.0 Winforms is the new BackgroundWorker component. It allows safely executing long tasks in a different thread than the GUI, while allowing an easy event-driven interface to perform the task and respond to events (such as detecting work progress). There are even [versions of this for .NET 1.1](http://weblogs.asp.net/rosherove/archive/2004/06/16/156948.aspx) courtesy of [Juval Lowy](http://www.idesign.net/).

One of the things it does **not** support is the ability to Cancel the running task **immediately** rather than waiting for the code to process the Cancel Request (which is vital if your “DoWork” code contains tasks that individually take a long time to process). With some Reflectoring, I was able to overcome this obstacle and provide a solution for this problem.

For the full details and download in VB.NET and C#, read the full article:

[Creating a better BackgroundWorker: CancelImmediately and other goodies](http://weblogs.asp.net/rosherove/articles/BackgroundWorkerEx.aspx)

## More in .Net 2.0

[All posts in .Net 2.0](https://osherove.com/blog/category/net-2-0)

- Nov 10, 2005

    ### [Microsoft solves my RTM Bug (By Design..)](https://osherove.com/blog/2005/11/10/microsoft-solves-my-rtm-bug-by-design.html)

- Nov 9, 2005

    ### [I'll be speaking at IVCUG this month: New stuff in .NET and C# 2.0 + Deep LINQ Preview](https://osherove.com/blog/2005/11/9/ill-be-speaking-at-ivcug-this-month-new-stuff-in-net-and-c-2.html)

- Nov 9, 2005

    ### [A better Safe Cast using Generics](https://osherove.com/blog/2005/11/9/a-better-safe-cast-using-generics.html)

- Nov 4, 2005

    ### [My first real frustration with VS 2005 RTM](https://osherove.com/blog/2005/11/4/my-first-real-frustration-with-vs-2005-rtm.html)


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
