backgroundworker

Pass values from BackgroundWorker DoWork to BackgroundWorker Completed

情到浓时终转凉″ 提交于 2019-12-11 00:04:38
问题 How do I pass a value from BackgroundWorker DoWork to BackgroundWorker Completed ? Since BackgroundWorker Completed is not called by BackgroundWorker DoWork I am not sure how to do this except declare a public variable . Essentially, I want BackgroundWorker Completed to accept through ByVal a variable from BackgroundWorker DoWork . 回答1: When you declare your DoWork function, note that it has some handy arguments built in : Private Sub backgroundWorker1_DoWork(sender As Object, e As

VB.Net - Updating progress bar from background worker

纵然是瞬间 提交于 2019-12-10 23:37:06
问题 I am trying to build a log parser in VB.Net that will take IIS logs and insert them into a database. Having never really made a full out desktop application, I'm hitting a number of stumbling blocks, so please forgive me if my questions a very uninformed; I'm learning to walk while running. The code that I'm working with looks like this: Protected Overrides Sub OnLoad(ByVal e As System.EventArgs) MyBase.OnLoad(e) BackgroundWorker1.RunWorkerAsync() End Sub Private Sub BackgroundWorker1_DoWork

TargetInvocationException from BackgroundWorker_RunWorkerCompleted

扶醉桌前 提交于 2019-12-10 22:17:29
问题 Suppose the following situation. A form has a button that on click starts a background worker. In RunWorkerCompleted event handler there is a piece of code that throws unhandeled exception. The form is started from Application.Run method. public partial class FormMain : Form { public FormMain() { InitializeComponent(); } private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { throw new Exception(); } private void button_Click(object sender, EventArgs e

Can I use too many background worker threads?

↘锁芯ラ 提交于 2019-12-10 19:44:55
问题 Each time my code needs to talk to the network or a database I use a backgroundworker, can I use too many, what is the correct way of doing these tasks? If I don't use a background worker the gui locks up if a remote host is down etc so using a backgroundworker is the only way I know to fix this. I'm self taught so I'm learning as I go along, thanks to all who answer. 回答1: Yes, you can use too many. BackgroundWorker uses threads from the threadpool, so if you start too many (simultaneously)

How to properly handle form closing when using background workers?

房东的猫 提交于 2019-12-10 19:12:07
问题 I am observing a strange bug in some of my code which I suspect is tied to the way closing a form and background workers interact. Here is the code potentially at fault: var worker = new BackgroundWorker(); worker.DoWork += (sender, args) => { command(); }; worker.RunWorkerCompleted += (sender, args) => { cleanup(); if (args.Error != null) MessageBox.Show("...", "...", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); }; worker.RunWorkerAsync(); This code is executed in a method in a form,

Creating a WPF Window from a WinForms BackgroundWorker

谁说我不能喝 提交于 2019-12-10 18:45:43
问题 I have a WPF dll that contains a number of Window classes and exposes methods that display those windows. I also have a separate WinForms project that is calling one of those methods in the WPF project inside the DoWork method of a BackgroundWorker component. On the line of code that instantiates a WPF Window, I get the following runtime error: The calling thread must be STA, because many UI components require this. A google search let me to this discussion. (Turns out Jon Skeet answers

How do I use MethodInvoker in C++?

眉间皱痕 提交于 2019-12-10 18:14:48
问题 I've got a C++/CLI application which has a background thread. Every so often I'd like it to post it's results to the main GUI. I've read elsewhere on SO that MethodInvoker could work for this, but I'm struggling to convert the syntax from C# to C++: void UpdateProcessorTemperatures(array<float>^ temperatures) { MethodInvoker^ action = delegate { const int numOfTemps = temperatures->Length; if( numOfTemps > 0 ) { m_txtProcessor2Temperature->Text = temperatures[0]; } else { m

Running class as new thread

血红的双手。 提交于 2019-12-10 17:28:39
问题 I want to start a job in a new thread or using backgroundworker to do it but havent done that before and asking you wich way I should do it. My program has a datagridview with a list of files, one file per row. I want the user to be able to select a row and then press "Start download" to start a background job of the download. I want to get events back of the progress of the download. I have a class clsDownload that handles everything and raises events back but how do I implement the

Manual stop debugging with backgroundworker

余生长醉 提交于 2019-12-10 17:25:38
问题 I am writing a WPF C# project with use of BackgroundWorker (a popup window with progress bar). I start debugging (F5 key) to check my program. After the BackgroundWorker is completed and the popup window is closed, closing the MainWindow does not automatically stop the debugging process. I have to manually hit Shift+F5 to stop the debugging. I thought BackgroundWorker should have taken care of the Thread automatically. But anyhow, I still call backgroundworker.Dispose() and backgroundworker

Trying to step through BackgroundWorker code in debug but program ends unexpectedly

痴心易碎 提交于 2019-12-10 16:40:18
问题 Here is the code I am working with: try { mainWorker = new BackgroundWorker(); mainWorker.DoWork += (sender, e) => { try { //stuff I want to have happen in the background ... //I want to step through the lines in this try block } catch { //exception not being caught } }; mainWorker.RunWorkerCompleted += (sender, e) => { //code to let user know that the background work is done ... }; mainWorker.RunWorkerAsync(); mainWorker.Dispose(); } catch { //exception not being caught } I do not see any