---
title: "How to use WPF Background Worker"  
description: "How to use WPF Background Worker"  
author: "Takeshi Okada"  
published: 2013-09-24  
updated: 2013-09-24  
canonical: https://www.mindstick.com/forum/1520/how-to-use-wpf-background-worker  
category: "wpf"  
tags: ["wpf"]  
reading_time: 2 minutes  

---

# How to use WPF Background Worker

I am a [beginner](https://www.mindstick.com/forum/23159/need-beginner-project-ideas) with WPF, in my [application](https://www.mindstick.com/articles/12824/calculator-application-in-android) I need to preform a series of Initialisation steps, these take 7-8 seconds to complete during which my UI [becomes unresponsive](https://answers.mindstick.com/qa/109186/what-to-do-if-my-phone-s-screen-freezes-and-becomes-unresponsive). To [resolve](https://www.mindstick.com/forum/159427/windows-app-dll-not-found-resolve-library-issue) this I preform the initialisation in a separate thread:

[public void](https://www.mindstick.com/interview/2715/can-we-write-static-public-void-instead-of-public-static-void) [Initialization](https://www.mindstick.com/interview/160/what-is-the-difference-between-assignment-and-initialization)()

{

Thread initThread = new Thread(new ThreadStart(InitializationThread));

initThread.Start();

}

public void InitializationThread()

{

outputMessage("Initializing...");

//DO INITIALIZATION

outputMessage("Initialization Complete");

}

I have read a few [articles](https://www.mindstick.com/articles/12872/how-to-write-articles-of-50-and-more-a-day-quick-and-easy) about the BackgroundWorker and how it should allow me to keep my application [responsive](https://www.mindstick.com/blog/11940/tips-for-fast-responsive-web-design-in-2018) without ever having to write a thread to preform lengthy tasks but I haven't had any [success](https://www.mindstick.com/articles/12957/best-tips-to-make-your-ghostwriting-experience-a-success) trying to implement it, could [anyone](https://www.mindstick.com/articles/23207/how-to-find-the-best-fit-job-for-anyone) tell how I would do this using the BackgroundWorker?

## Replies

### Reply by Pravesh Singh

Hi Takeshi,

Add following using: using System.ComponentModel;

## 1.Declare backgrownd worker:

private readonly BackgroundWorker worker = new BackgroundWorker();

## 2.Subscribe to events:

worker.DoWork += worker_DoWork;

worker.RunWorkerCompleted += worker_RunWorkerCompleted;

## 3.Implement two methods:

```
private void worker_DoWork(object sender, DoWorkEventArgs e){   // run all background tasks here}private void worker_RunWorkerCompleted(object sender,                                       RunWorkerCompletedEventArgs e){  //update ui once worker complete his work}
```

**4.Run worker async whenever your need.**

worker.RunWorkerAsync();

Also if you want to report process progress you should subscribe to ProgressChanged event and use ReportProgress(Int32) in DoWork method to raise an event. Also set following: worker.WorkerReportsProgress = true; (thanks to @zagy)

Hope this help.


---

Original Source: https://www.mindstick.com/forum/1520/how-to-use-wpf-background-worker

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
