backgroundworker

C# Downloader: should I use Threads, BackgroundWorker or ThreadPool?

谁说胖子不能爱 提交于 2019-11-26 20:21:40
问题 I'm writing a downloader in C# and stopped at the following problem: what kind of method should I use to parallelize my downloads and update my GUI? In my first attempt, I used 4 Threads and at the completion of each of them I started another one: main problem was that my cpu goes 100% at each new thread start. Googling around, I found the existence of BackgroundWorker and ThreadPool: stating that I want to update my GUI with the progress of each link that I'm downloading, what is the best

Backgroundworker won't report progress

十年热恋 提交于 2019-11-26 20:14:13
问题 I have a background worker running a long database task. i want to show the progress bar while the task is running. Somehow the background worker won't report the progress of the task. This is what i have: BackgroundWorker _bgwLoadClients; _bgwLoadClients = new BackgroundWorker(); _bgwLoadClients.WorkerReportsProgress = true; _bgwLoadClients.DoWork += new DoWorkEventHandler(_bgwLoadClients_DoWork); _bgwLoadClients.RunWorkerCompleted += new RunWorkerCompletedEventHandler(_bgwLoadClients

Unhandled exceptions in BackgroundWorker

时光总嘲笑我的痴心妄想 提交于 2019-11-26 19:41:24
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 me. I'm getting occasional DatabaseExceptions in some of these background threads, and I have witnessed at least one of these exceptions in a worker thread while debugging. I'm fairly confident these exceptions are timeouts which I suppose its reasonable to expect from time to time. My question is about what happens when an unhandled exception

Unhandled exceptions in BackgroundWorker

不想你离开。 提交于 2019-11-26 18:41:15
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 the code is run from the IDE or not .NET pops up an error dialog informing the user that an Unhandled exception has occurred. Compiling the code using the Release configuration doesn't change this either. According to MSDN : If the operation raises an exception that your code does not handle, the BackgroundWorker catches the exception and passes it

How to cancel a long-running Database operation?

馋奶兔 提交于 2019-11-26 17:32:27
问题 Currently working with Oracle, but will also need a solution for MS SQL. I have a GUI that allows users to generate SQL that will be executed on the database. This can take a very long time, depending on the search they generate. I want the GUI/App to responsive during this search and I want the user to be able to cancel the search. I'm using a Background Worker Thread. My problem is that, when the user cancels the search, I can't interrupt the call to the database. It waits until it is

Thread/threadpool or backgroundworker

拥有回忆 提交于 2019-11-26 16:29:55
问题 I would like to know what to use for tasks that need alot of performance. Backgroundworker , Thread or ThreadPool ? I've been working with Threads so far, but I need to improve speed of my applications. 回答1: BackgroundWorker is the same thing as a thread pool thread. It adds the ability to run events on the UI thread. Very useful to show progress and to update the UI with the result. So its typical usage is to prevent the UI from freezing when works needs to be done. Performance is not the

How to “kill” background worker completely?

半腔热情 提交于 2019-11-26 15:53:56
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 occasions when I get the "This backgroundworker is currently busy......." error message. I am thinking of implementing the following in the code, by using a while loop to "kill" the background worker before starting another sequence of action: if (backgroundWorker1.IsBusy == true) { backgroundWorker1.CancelAsync(); while (backgroundWorker1.IsBusy ==

Task parallel library replacement for BackgroundWorker?

浪尽此生 提交于 2019-11-26 15:45:25
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 a responsive UI with the standard progress bar and ability to cancel the operation. I've done this before with BackgroundWorker, but I'm wondering if there are some TPL patterns that can be used instead? The Task class is an improvement over the BackgroundWorker ; it naturally supports nesting (parent/child tasks), uses the new cancellation API,

How to wait correctly until BackgroundWorker completes?

梦想的初衷 提交于 2019-11-26 15:27:41
问题 Observe the following piece of code: var handler = GetTheRightHandler(); var bw = new BackgroundWorker(); bw.RunWorkerCompleted += OnAsyncOperationCompleted; bw.DoWork += OnDoWorkLoadChildren; bw.RunWorkerAsync(handler); Now suppose I want to wait until bw finishes working. What is the right way to do so? My solution is this: bool finished = false; var handler = GetTheRightHandler(); var bw = new BackgroundWorker(); bw.RunWorkerCompleted += (sender, args) => { OnAsyncOperationCompleted(sender

Get File Size on FTP Server and put it on a Label

守給你的承諾、 提交于 2019-11-26 14:57:40
问题 I'm trying to get the size of a file that is hosted on a FTP Server and put it in a Label while the `BackgroundWorker works in the background. I'm using " Try " to get the value, however the value is caught on the first attempt. After downloading, if I press to try to get it again then it works. Note : The progress bar also does not work on the first try. Image What I have tried: Private Sub BWorkerD_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BWorkerD.DoWork