backgroundworker

which thread does backgroundworker completed event handler run on?

风流意气都作罢 提交于 2019-12-22 04:18:20
问题 I have a GUI application that needs to run long calculations (think a minute or more) and the way that it deals with this is by giving the calculation to a background worker. (this part is fine) The question I have is if I do something like: this.backgroundWorker.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.doSomethingElse); is doSomethingElse going to be run on the main UI thread or whatever in the thread pool the background worker ran on? thank for any

Backgroundworker in python

情到浓时终转凉″ 提交于 2019-12-21 20:44:43
问题 I'm an inexperienced python programmer. Is there a way to use the backgroundworker so that it starts at program startup and closes when program close? I want it to watch a button, the button returns 1 when pressed. So while the program in running whenever button = 1 button has to do "this". Can anyone help me with this? 回答1: Would make sense to start a separate thread within your main program and do anything in the background. As an example check the fairly simple code below: import threading

Backgroundworker CancelAsync() won't work

寵の児 提交于 2019-12-21 17:33:04
问题 I am trying to cancel my Backgroundworker with WorkerClass.bw.CancelAsync() . But it wont work at all. //edit! I posted the full Code here. May this will help. Okay, i added some Msgboxes to know if the Worker is still busy and the wired thing is, that i get a false while the worker is doing things!?!? Public Class Form1 Private Sub btn_start_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_start.Click Dim WorkerClass As New BGWClass WorkerClass.bw

How can I scan and transfer images from a document feeder asynchronously

混江龙づ霸主 提交于 2019-12-21 12:31:37
问题 Which parts of the communication with TWAIN can be put into another thread, e.g. a BackgroundWorker? Or: Is it possible to split the loop that handles the image transfer? Some scanner drivers scan all images before returning to the calling application which forces the application to handle all images at once. This results in e.g. OutOfMemoryException or weird behavior in my WPF application when suddenly all events (raised after every scanned image) have to be handled at once. Additionally the

Can a Heroku app add/remove dynos or workers to/from itself?

*爱你&永不变心* 提交于 2019-12-21 06:36:41
问题 Heroku allows you to add and remove dynos and workers on the fly and charges you per second that each is used. Is it possible to set up my app so that it can add/remove dynos and workers from itself depending on the load it's under? This paragraph on Heroku.com mentions an API, but I can't find out much more about it. 回答1: Yes. What you want is something like this: require 'heroku' Heroku::Client.new("username", "password").set_workers("appname", num_workers) 来源: https://stackoverflow.com

WPF: How to handle errors with a BackgroundWorker

血红的双手。 提交于 2019-12-21 06:15:29
问题 I am a bit of a newbie when it comes to windows client programming. I have a background worker that has a DoWork event and a RunCompleted event wired up. If an exception gets thrown in DoWork, I want to make changes to my UI, however, I cant because it is in a different thread. I can communicate the error to RunCompleted, but that doesn't help me either. 回答1: call Dispatcher.BeginInvoke. Basically, you want code like this: void UpdateState(WhatEverType someObject) { if (! Dispatcher

The right way to implement a progressbar in C#

强颜欢笑 提交于 2019-12-21 05:22:26
问题 I'm learning winforms and I have set myself a simple goal of making a progressbar that goes from empty to full. Here's my misshapen attempt: public partial class Form1 : Form { static BackgroundWorker bw = new BackgroundWorker(); public Form1() { InitializeComponent(); bw.DoWork += bw_DoWork; bw.RunWorkerAsync(); } void bw_DoWork(object sender, DoWorkEventArgs e) { for(int i=0; i<100; ++i) { progressBar1.PerformStep(); Thread.Sleep(10); } } } I'm pretty sure that the Thread.Sleep() is

WPF Dispatcher, Background worker and a whole lot of pain

十年热恋 提交于 2019-12-21 05:08:13
问题 Ok this may be really simple but everything I try just seems to hit a brick wall. I have a view model with two properties, which are bound to my WPF form: bool IsWorking {get;set;} ObservableCollection<OtherViewModel> PendingItems {get;set;} I have a method that I call to fetch some new pending items from outlook, however I also what to show some sort of progress on the form(spinning progress bar), the progress bar visibility is bound to the IsWorking property on the ViewModel, and a grid is

Convert a WPF dispatcher to Winforms BGworker?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-20 06:21:58
问题 i recently acquired some source code for a console wrapper for a server. The program was originaly in WPF and part of the code was: private void ServerProc_ErrorDataReceived(object sender, DataReceivedEventArgs e) { Dispatcher.Invoke(new Action(() => { ConsoleTextBlock.Text += e.Data + "\r\n"; ConsoleScroll.ScrollToEnd(); })); } private void ServerProc_OutputDataReceived(object sender, DataReceivedEventArgs e) { Dispatcher.Invoke(new Action(() => { ConsoleTextBlock.Text += e.Data + "\r\n";

BackgroundWorker thread to Update WinForms UI

只谈情不闲聊 提交于 2019-12-20 03:40:17
问题 I am trying to update a label from a BackgroundWorker thread that calls a method from another class outside the Form. So I basically want to do this: MainForm.counterLabel.Text = Counter.ToString(); but the label is private. I have looked into things like using BackgroundWorker's progressupdate function, invoke, etc but they don't seem to be what I need. here is some more of my code: the MainForm: clickThread.DoWork += (s, o) => { theClicker.Execute(speed); }; clickThread.RunWorkerAsync();