backgroundworker

Update label from mainform class with backgroundworker from another class

别说谁变了你拦得住时间么 提交于 2019-12-01 21:27:48
I have two classes. Public Class MainForm Private Project As clsProject Private Sub btnDo_Click ... Backgroundworker.RunWorkerAsync() End Sub Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork Project = New clsProject End Sub and two methods inside MainForm Public Shared Sub setLabelTxt(ByVal text As String, ByVal lbl As Label) If lbl.InvokeRequired Then lbl.Invoke(New setLabelTxtInvoker(AddressOf setLabelTxt), text, lbl) Else lbl.Text = text End If End Sub Public Delegate Sub setLabelTxtInvoker

Showing Modal Window while BackgroundWorker runs, without getting STA/MTA issue

十年热恋 提交于 2019-12-01 21:08:10
I am working on a WPF application. I have a time consuming method that I want to run async via BackgroundWorker . While the method runs, I want to display a modal "Please Wait..." dialog window, which must automatically close when the BackgroundWorker completes. I currently have very little experience with BackgroundWorker or any multi threaded programming. The code below currently results in an InvalidOperationException , with the message "The calling thread must be STA, because many UI components require this." Please advise me on how to achieve what I am trying to achieve, and extra brownie

How to wait for background worker to finish processing?

纵饮孤独 提交于 2019-12-01 21:06:31
问题 I have 3 background workers each processing a channel of a 24-bit Bitmap image (Y, Cb, Cr). The processing for each 8-bit image takes several seconds and they might not complete at the same time. I want to merge the channels back into one image when I'm done. When a button is clicked, each of the backgroundWorkerN.RunWorkerAsync() is started and when they complete I set a flag for true. I tried using a while loop while (!y && !cb && !cr) { } to continually check the flags until they are true

How close BackgroundWorker thread when application is deactivated?

丶灬走出姿态 提交于 2019-12-01 18:37:21
问题 I create thread with BackgroundWorker , and in the loop I check every time if CancellationPending is true or not, like this: public MainPage() { InitializeComponent(); bw = new BackgroundWorker(); bw.WorkerReportsProgress = true; bw.WorkerSupportsCancellation = true; bw.DoWork += new DoWorkEventHandler(bw_DoWork); bw.ProgressChanged += new ProgressChangedEventHandler(bw_ProgressChanged); bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted); } private void

How close BackgroundWorker thread when application is deactivated?

和自甴很熟 提交于 2019-12-01 17:54:36
I create thread with BackgroundWorker , and in the loop I check every time if CancellationPending is true or not, like this: public MainPage() { InitializeComponent(); bw = new BackgroundWorker(); bw.WorkerReportsProgress = true; bw.WorkerSupportsCancellation = true; bw.DoWork += new DoWorkEventHandler(bw_DoWork); bw.ProgressChanged += new ProgressChangedEventHandler(bw_ProgressChanged); bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted); } private void ButtonStart_Click(object sender, RoutedEventArgs e) { if (bw.IsBusy != true) { bw.RunWorkerAsync(); } }

How to use the BackgroundWorker event RunWorkerCompleted

故事扮演 提交于 2019-12-01 16:45:40
All,I already knew the basic usage the BackgroundWorker to handle multiple thread case in the WinForm . And the code structure looks like below. In the main thread of application. just start the BackgroundWork. if (backgroundWorker1.IsBusy != true) { // Start the asynchronous operation. backgroundWorker1.RunWorkerAsync(); } Then it would fire the DoWork event . So we can do something in there. private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; ...... // report progress. worker.ReportProgress(iProgress); .... } Then we

Is it possible to kill the BackgroundWorker's thread?

*爱你&永不变心* 提交于 2019-12-01 16:44:01
问题 Is it possible "kill" the thread of a BackgroundWorker ? In my DoWork event, I can't check the cancellation flag, because I have a blocking call to an external COM interface or a query to a database. CancelAsync doesn't cancel the call to COM. How can I do it, please ? Any suggestions will be very appreciated. Thanks in advance. 回答1: I'm not aware of a safe way to abort a thread. A background worker can check if it should cancel and cancel itself, but if it's off querying a database there's

C# Multiple BackgroundWorkers

 ̄綄美尐妖づ 提交于 2019-12-01 15:48:09
I am trying to setup multiple BackgroundWorker s to do work and when not busy start doing the next bit of work. I can't seem to get them working properly. I have the below code. When I set FilesToProcess equal or less than MaxThreads it works perfectly although if I make it higher, the app freezes. I am sure it is something simple, but I just can't see it. using System; using System.ComponentModel; using System.Threading; using System.Windows.Forms; namespace bgwtest { public partial class Form1 : Form { private const int MaxThreads = 20; private const int FilesToProcess = 21; private

background worker(threadpool) in asp.net

假如想象 提交于 2019-12-01 14:02:27
I have a asp.net webform which writes about 25-30 items(has info required when user makes follow up request from the form) into a custom cache. Currently all this happens synchronously on the main thread. But at higher loads addcache is becoming a bottleneck. How can i run this task in the background without consuming threads from the asp.net worker process thread pool. Jupaol Alternatives: Completely async: Call the server code using AJAX from the client, and add code to monitor the process of the call I just added an answer related to this process: https://stackoverflow.com/a/11524718

background worker(threadpool) in asp.net

一个人想着一个人 提交于 2019-12-01 12:33:13
问题 I have a asp.net webform which writes about 25-30 items(has info required when user makes follow up request from the form) into a custom cache. Currently all this happens synchronously on the main thread. But at higher loads addcache is becoming a bottleneck. How can i run this task in the background without consuming threads from the asp.net worker process thread pool. 回答1: Alternatives: Completely async: Call the server code using AJAX from the client, and add code to monitor the process of