backgroundworker

Background Worker: Make sure that ProgressChanged method has finished before executing RunWorkerCompleted

帅比萌擦擦* 提交于 2019-12-22 18:14:12
问题 Let's assume I'm using a Background Worker and I've the following methods: private void bw_DoWork(object sender, DoWorkEventArgs e) { finalData = MyWork(sender as BackgroundWorker, e); } private void bw_ProgressChanged(object sender, ProgressChangedEventArgs e) { int i = e.ProgressPercentage; // Missused for i Debug.Print("BW Progress Changed Begin, i: " + i + ", ThreadId: " + Thread.CurrentThread.ManagedThreadId); // I use this to update a table and an XY-Plot, so that the user can see the

BackgroundWorker cancellation

自作多情 提交于 2019-12-22 12:27:47
问题 I am using a BackgroundWorker in my winforms app to perform a long running task that occurs in another class (performing database operations). Since all the work is done in another class the cancellation is not as simple. I am using an event in the other class ( GenerateStats ) to update the progress as the background operation completes. I want to do a similar thing with cancelling the operation. I can't just call cancellationPending in the DoWork function because the method would never see

How to run Matlab computations in parallel

空扰寡人 提交于 2019-12-22 12:19:57
问题 I have Matlab .m script that sets and trains Neural network ("nn") using Matlab's Neural network toolbox. The script launches some GUI that shows trainig progress etc. The training of nn usually takes long time. I'm doing these experiments on computer with 64 processor cores. I want to train several networks at the same time without having to run multiple Matlab sessions. So I want to: Start training of neural network Modify script that creates network to create different one Start training

Correctly loading a document on a background thread

喜夏-厌秋 提交于 2019-12-22 08:47:42
问题 From apps I've written and one I've inherited, I have a continuing desire to better understand the thread-safety issues of loading data on a background thread. Suppose I have a simple, single-window Windows Forms app with a "Load" button and a BackgroundWorker : The button's Click handler calls loadBackgroundWorker.RunWorkerAsync() , and the worker's DoWork handler creates and initializes an object of type Document which, after loading, it stores in the form's LoadedDocument property. In the

Slow to set DataGridView DataSource to DataTable in C#

两盒软妹~` 提交于 2019-12-22 08:34:45
问题 I have a DataTable, fully populated, which I want to set to a DatagridView: gdv.DataSource = dt; However, this is painfully slow. The filling of the DataTable is very quick, but just this one line above takes ages. Is there any way to speed this up or perform it in another thread? There is no interaction after this point. Just the simple statement above! Thanks. 回答1: Check the formatting options, especially the Fill -related properties. Adjusting columnwidths for all rows involves a lot of

Using Console.WriteLine in a BackgroundWorker doWork event

那年仲夏 提交于 2019-12-22 08:31:20
问题 I have a console application that utilizes the BackgroundWorker object and wanted to test my output with a Console.WriteLine(fooBar). However, that application exits as the application executes the Console.WriteLine command. Here's a watered down version that illustrates what I wanted to do: protected static void bWorker_DoWork(object sender, DoWorkEventArgs e) { for (int i = startId; i <= endId; i++) { Console.WriteLine(i.ToString()); Thread.Sleep(1000); } } Any ideas why the application

Convert Ping application to multithreaded version to increase speed - C#

大憨熊 提交于 2019-12-22 05:39:45
问题 I have an application that pings every possible IP on your local subnet in order to compile a list of responsive IP addresses. Currently it pings all 255 one at a time. Is it possible to convert this app to use multiple threads to increase the speed by pinging more than one at a time? I am new to the concept of multiple threads and figure this would be a good way to learn(as long as it's possible of course). also, any stylistic improvements you can educate me on would also be helpful. thanks

Updating the GUI from background worker

心不动则不痛 提交于 2019-12-22 05:19:06
问题 The name of the question is: " Updating the GUI from background worker ", but the correct name world be: " Updating the GUI from background worker OR reporting multiple-variables (other than an integer) from background worker " Please let me explain my situation. In a program I have a background worker which analyses the information.As the result of this analysis - form GUI elements should be populated with necessary data. In GUI I would like to update 2 datagridviews 1 listbox 5 labels As I

C# / VB.Net Task vs Thread vs BackgroundWorker

眉间皱痕 提交于 2019-12-22 05:06:38
问题 I have "Googled" but still confused with Task, Thread, and Background Worker..... Is "Task is a high level API that running on current thread" correct ? If 1 is correct, why I need to use invoke to change the UI inside the task at same thread ? Backgroundworker only got lowest priority in the application ? So the performance of backgroundworker is lower than task and thread ? Right ? Finally, in my application I need to get a string from server using "HttpWebRequest", after that parse the

WPF MVVM updating the View Model on a Background Worker

人走茶凉 提交于 2019-12-22 04:47:19
问题 Is this senerio valid? I have a View to maintain an Item. I have View Model which exposes the Item Object (implements INotifyPropertyChanged) as a Property to which is View is bound. Is it valid for me to pass the Item object to a Backgroundworker where it is modified, then raise the PropertyChanged event when the BackgroundWorking is complete? Or should the BackgroundWorker in no way modify the Item object. I would update the existing Item object with the results passed back by the