Questions tagged [backgroundworker]

BackgroundWorker is a helper class in .NET's System.ComponentModel namespace providing a general implementation of the Event-Based Asynchronous Pattern to manage a worker thread, support cooperative cancellation, and report progress.

BackgroundWorker is a helper class in .NET's System.ComponentModel namespace providing a general implementation of the Event-Based Asynchronous Pattern to manage a worker thread, support cooperative cancellation, and report progress.

3484 questions
429
votes
15 answers

The calling thread cannot access this object because a different thread owns it

My code is as below public CountryStandards() { InitializeComponent(); try { FillPageControls(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Country Standards", MessageBoxButton.OK,…
Kuntady Nithesh
  • 11,371
  • 20
  • 63
  • 86
192
votes
4 answers

How to use WPF Background Worker

In my application I need to perform a series of initialization steps, these take 7-8 seconds to complete during which my UI becomes unresponsive. To resolve this I perform the initialization in a separate thread: public void Initialization() { …
Eamonn McEvoy
  • 8,876
  • 14
  • 53
  • 83
190
votes
5 answers

Async/await vs BackgroundWorker

In the past few days I have tested the new features of .net 4.5 and c# 5. I like its new async/await features. Earlier I had used BackgroundWorker to handle longer processes in the background with responsive UI. My question is: after having these…
Tom
  • 3,899
  • 22
  • 78
  • 137
183
votes
12 answers

BackgroundWorker vs background Thread

I have a stylistic question about the choice of background thread implementation I should use on a windows form app. Currently I have a BackgroundWorker on a form that has an infinite (while(true)) loop. In this loop I use WaitHandle.WaitAny to keep…
freddy smith
  • 3,347
  • 5
  • 24
  • 28
168
votes
8 answers

Sending Arguments To Background Worker?

Let's say I want to sent an int parameter to a background worker, how can this be accomplished? private void worker_DoWork(object sender, DoWorkEventArgs e) { } I know when this is worker.RunWorkerAsync();, I don't understand how to define in…
sooprise
  • 22,657
  • 67
  • 188
  • 276
127
votes
18 answers

How to wait for a BackgroundWorker to cancel?

Consider a hypothetical method of an object that does stuff for you: public class DoesStuff { BackgroundWorker _worker = new BackgroundWorker(); ... public void CancelDoingStuff() { _worker.CancelAsync(); //todo:…
Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
84
votes
2 answers

Task parallel library replacement for BackgroundWorker?

Does the task parallel library have anything that would be considered a replacement or improvement over the BackgroundWorker class? I have a WinForms application with a wizard-style UI, and it does some long-running tasks. I want to be able to have…
Keith G
  • 4,580
  • 5
  • 38
  • 48
82
votes
2 answers

How to use a BackgroundWorker?

I know it has 3 methods. In my program I have a method to send a message. It is often late and the program sometimes doesn't send the message at all in response to a button press. At times it is as late as 5 seconds from what I would expect and the…
angel
  • 4,474
  • 12
  • 57
  • 89
78
votes
8 answers

How to stop BackgroundWorker correctly

I have a form with 2 comboboxes on it. And I want to fill combobox2.DataSource based on combobox1.Text and combobox2.Text (I assume that the user has completed input in combobox1 and is in the middle of inputting in combobox2). So I have an event…
StuffHappens
  • 6,457
  • 13
  • 70
  • 95
75
votes
12 answers

How to stop BackgroundWorker on Form's Closing event?

I have a form that spawns a BackgroundWorker, that should update form's own textbox (on main thread), hence Invoke((Action) (...)); call. If in HandleClosingEvent I just do bgWorker.CancelAsync() then I get ObjectDisposedException on Invoke(...)…
THX-1138
  • 21,316
  • 26
  • 96
  • 160
75
votes
5 answers

Unhandled exceptions in BackgroundWorker

I have a small WinForms app that utilizes a BackgroundWorker object to perform a long-running operation. The background operation throws occasional exceptions, typically when somebody has a file open that is being recreated. Regardless of whether…
Andy
  • 821
  • 2
  • 7
  • 8
73
votes
5 answers

Unhandled exceptions in BackgroundWorker

My WinForms app uses a number of BackgroundWorker objects to retrieve information from a database. I'm using BackgroundWorker because it allows the UI to remain unblocked during long-running database queries and it simplifies the threading model for…
Ed Guiness
  • 34,602
  • 16
  • 110
  • 145
62
votes
8 answers

How to make BackgroundWorker return an object

I need to make RunWorkerAsync() return a List. What is the process to be able to return an object from a background worker?
Clair Vengs
58
votes
6 answers

How to "kill" background worker completely?

I am writing a windows application that runs a sequence of digital IO actions repeatedly. This sequence of actions starts when the user click a "START" button, and it is done by a background worker in backgroundWorker1_DoWork(). However, there are…
Ken Hung
58
votes
4 answers

This BackgroundWorker is currently busy and cannot run multiple tasks concurrently

I get this error if I click a button that starts the backgroundworker twice. This BackgroundWorker is currently busy and cannot run multiple tasks concurrently How can I avoid this?
Jade M
1
2 3
99 100