backgroundworker

Cancelling Background Tasks

扶醉桌前 提交于 2019-12-03 13:17:08
问题 When my C# application closes it sometimes gets caught in the cleanup routine. Specifically, a background worker is not closing. This is basically how I am attempting to close it: private void App_FormClosing(object sender, FormClosingEventArgs e) { backgroundWorker1.CancelAsync(); while (backgroundWorker1.IsBusy) ; // Gets stuck here. } Is there a different way that I should be doing this? I am using Microsoft Visual C# 2008 Express Edition. Thanks. ADDITIONAL INFORMATION: The background

Flask: passing around background worker job (rq, redis)

不问归期 提交于 2019-12-03 12:57:36
问题 I want to do a very simple thing: Launch a worker to something and then return the answer to user. I'm trying to do so using a combination of Flask and RQ. import os from flask import Flask, session from somewhere import do_something from rq import Queue from worker import conn app = Flask(__name__) app.debug = True app.secret_key = '....' q = Queue(connection=conn) @app.route('/make/') def make(): job = q.enqueue(do_something, 'argument') session['job'] = job return 'Done' @app.route('/get/'

Using a background worker in ASP.NET with AJAX

徘徊边缘 提交于 2019-12-03 12:55:29
问题 I have the need to perform a background task that has a progress bar that shows percentage done and a cancel button. Task specifics aside, for now, I just want to get an example working, so I just have the three main event handlers (DoWork, ProgressChanged, and RunWorkerCompleted) and a loop that just increments a counter and sleeps for 50ms in DoWork. However, it doesn't update except for once at the end. In Windows Forms I use a Background worker and it functions correctly without any

Using BackgroundWorker to update the UI without freezes…?

拥有回忆 提交于 2019-12-03 08:46:11
I have the following code for population a ListView from a background thread (DoWork calls the PopulateThread method): delegate void PopulateThreadCallBack(DoWorkEventArgs e); private void PopulateThread(DoWorkEventArgs e) { if (this.InvokeRequired) { PopulateThreadCallBack d = new PopulateThreadCallBack(this.PopulateThread); this.Invoke(d, new object[] { e }); } else { // Ensure there is some data if (this.DataCollection == null) { return; } this.Hide(); // Filter the collection based on the filters List<ServiceCallEntity> resultCollection = this.ApplyFilter(); // Get the current Ids List

Replacing methods that use backgroundworker to async / tpl (.NET 4.0)

断了今生、忘了曾经 提交于 2019-12-03 08:11:05
问题 My questions are many. Since I saw. NET 4.5, I was very impressed. Unfortunately all my projects are .NET 4.0 and I am not thinking about migrating. So I would like to simplify my code. Currently, most of my code that usually take enough time to freeze the screen, I do the following: BackgroundWorker bd = new BackgroundWorker(); bd.DoWork += (a, r) => { r.Result = ProcessMethod(r.Argument); }; bd.RunWorkerCompleted += (a, r) => { UpdateView(r.Result); }; bd.RunWorkerAsync(args); Honestly, I'm

Best way to report thread progress

强颜欢笑 提交于 2019-12-03 07:51:43
I have a program that uses threads to perform time-consuming processes sequentially. I want to be able to monitor the progress of each thread similar to the way that the BackgroundWorker.ReportProgress / ProgressChanged model does. I can't use ThreadPool or BackgroundWorker due to other constraints I'm under. What is the best way to allow/expose this functionality. Overload the Thread class and add a property/event? Another more-elegant solution? Overload the Thread class and add a property/event? If by "overload" you actually mean inherit then no. The Thread is sealed so it cannot be

Updating background worker to async-await

为君一笑 提交于 2019-12-03 06:59:03
So this is how I currently use background worker to save a lot of stuff to file while presenting the user with a progress bar and preventing any changes to the UI while saving is in progress. I think I've captured the essential features. The modal ProgressWindow displays a progress bar and not much else. How would I go about changing this to async-await pattern, if I had to? private ProgressForm ProgressWindow { get; set; } /// <summary>On clicking save button, save stuff to file</summary> void SaveButtonClick(object sender, EventArgs e) { if (SaveFileDialog.ShowDialog() == DialogResult.OK) {

C#: Do I need to dispose a BackgroundWorker created at runtime?

那年仲夏 提交于 2019-12-03 04:13:44
问题 I typically have code like this on a form: private void PerformLongRunningOperation() { BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += delegate { // perform long running operation here }; worker.RunWorkerAsync(); } This means that I don't dispose the BackgroundWorker , whereas if I had added it by the form designer then I think it would get disposed. Will this cause any problems? Is it more correct to declare a module-level _saveWorker , and then call Dispose on it from

Flask: passing around background worker job (rq, redis)

僤鯓⒐⒋嵵緔 提交于 2019-12-03 03:08:01
I want to do a very simple thing: Launch a worker to something and then return the answer to user. I'm trying to do so using a combination of Flask and RQ. import os from flask import Flask, session from somewhere import do_something from rq import Queue from worker import conn app = Flask(__name__) app.debug = True app.secret_key = '....' q = Queue(connection=conn) @app.route('/make/') def make(): job = q.enqueue(do_something, 'argument') session['job'] = job return 'Done' @app.route('/get/') def get(): try: session['job'].refresh() out = str(session['job'].result) except: out = 'No result

Update textbox from loop in backgroundworker

佐手、 提交于 2019-12-02 22:44:37
问题 I know this questions gets asked a bit (at least from what I found here so far), but I can't really wrap my head around it. Already tried it with the example from msdn but still no succes. Here is what I'm trying to do: I have a USB-Counter connected to a TLL-ruler. I want to read the value constantly in a loop and write the readout to a textbox without blocking the main UI. I know from other questions that I should use Invoke or Backgroundworker, but have not really found an example which I