--- title: "BackgroundWorker Component Overview" ms.date: "03/30/2017" dev_langs: - "csharp" - "vb" - "cpp" f1_keywords: - "BackgroundWorker" helpviewer_keywords: - "BackgroundWorker component" - "background tasks" - "Asynchronous Pattern" - "forms [Windows Forms], multithreading" - "components [Windows Forms], asynchronous" - "forms [Windows Forms], background operations" - "threading [Windows Forms], background operations" - "background operations" ms.assetid: 64e9b3ab-7443-4a77-ab17-b8b8c0cb3f62 --- # BackgroundWorker Component Overview There are many commonly performed operations that can take a long time to execute. For example: - Image downloads - Web service invocations - File downloads and uploads (including for peer-to-peer applications) - Complex local computations - Database transactions - Local disk access, given its slow speed relative to memory access Operations like these can cause your user interface to block while they are running. When you want a responsive UI and you are faced with long delays associated with such operations, the component provides a convenient solution. The component gives you the ability to execute time-consuming operations asynchronously ("in the background"), on a thread different from your application's main UI thread. To use a , you simply tell it what time-consuming worker method to execute in the background, and then you call the method. Your calling thread continues to run normally while the worker method runs asynchronously. When the method is finished, the alerts the calling thread by firing the event, which optionally contains the results of the operation. The component is available from the **Toolbox**, in the **Components** tab. To add a to your form, drag the component onto your form. It appears in the component tray, and its properties appear in the **Properties** window. To start your asynchronous operation, use the method. takes an optional `object` parameter, which can be used to pass arguments to your worker method. The class exposes the event, to which your worker thread is attached through a event handler. The event handler takes a parameter, which has an property. This property receives the parameter from and can be passed to your worker method, which will be called in the event handler. The following example shows how to assign a result from a worker method called `ComputeFibonacci`. It is part of a larger example, which you can find at [How to: Implement a Form That Uses a Background Operation](how-to-implement-a-form-that-uses-a-background-operation.md). [!code-cpp[System.ComponentModel.BackgroundWorker#5](~/samples/snippets/cpp/VS_Snippets_Winforms/System.ComponentModel.BackgroundWorker/CPP/fibonacciform.cpp#5)] [!code-csharp[System.ComponentModel.BackgroundWorker#5](~/samples/snippets/csharp/VS_Snippets_Winforms/System.ComponentModel.BackgroundWorker/CS/fibonacciform.cs#5)] [!code-vb[System.ComponentModel.BackgroundWorker#5](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.ComponentModel.BackgroundWorker/VB/fibonacciform.vb#5)] For more information on using event handlers, see [Events](/dotnet/standard/events/index). > [!CAUTION] > When using multithreading of any sort, you potentially expose yourself to very serious and complex bugs. Consult the [Managed Threading Best Practices](/dotnet/standard/threading/managed-threading-best-practices) before implementing any solution that uses multithreading. For more information on using the class, see [How to: Run an Operation in the Background](how-to-run-an-operation-in-the-background.md). ## See also - [Managed Threading](/dotnet/standard/threading/index) - [Event-based Asynchronous Pattern Overview](/dotnet/standard/asynchronous-programming-patterns/event-based-asynchronous-pattern-overview) - [How to: Implement a Form That Uses a Background Operation](how-to-implement-a-form-that-uses-a-background-operation.md)