backgroundworker

report progress backgroundworker from different class c#

人走茶凉 提交于 2019-11-27 20:13:40
In my .NET C# project I have used a "BackgroundWorker" to call a method in a different class. The following is the source-code of my main form public partial class Form1 : Form { public Form1() { InitializeComponent(); } testClass t1 = new testClass(); private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { t1.changevalue(1000); } private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e) { label1.Text += Convert.ToString(e.ProgressPercentage); } private void button1_Click(object sender, EventArgs e) { backgroundWorker1.RunWorkerAsync(); } } and

Backgroundworker won't report progress

拜拜、爱过 提交于 2019-11-27 20:09:39
I have a background worker running a long database task. i want to show the progress bar while the task is running. Somehow the background worker won't report the progress of the task. This is what i have: BackgroundWorker _bgwLoadClients; _bgwLoadClients = new BackgroundWorker(); _bgwLoadClients.WorkerReportsProgress = true; _bgwLoadClients.DoWork += new DoWorkEventHandler(_bgwLoadClients_DoWork); _bgwLoadClients.RunWorkerCompleted += new RunWorkerCompletedEventHandler(_bgwLoadClients_RunWorkerCompleted); _bgwLoadClients.ProgressChanged += new ProgressChangedEventHandler(_bgwLoadClients

Winforms updates with high performance

别说谁变了你拦得住时间么 提交于 2019-11-27 19:38:35
问题 Let me setup this question with some background information, we have a long running process which will be generating data in a Windows Form. So, obviously some form of multi-threading is going to be needed to keep the form responsive. But, we also have the requirement that the form updates as many times per second while still remaining responsive. Here is a simple test example using background worker thread: void bw_ProgressChanged(object sender, ProgressChangedEventArgs e) { int reportValue

In WPF, what is the equivalent of Suspend/ResumeLayout() and BackgroundWorker() from Windows Forms

China☆狼群 提交于 2019-11-27 18:37:35
If I am in a function in the code behind, and I want to implement displaying a "Loading..." in the status bar the following makes sense, but as we know from WinForms is a NoNo: StatusBarMessageText.Text = "Loading Configuration Settings..."; LoadSettingsGridData(); StatusBarMessageText.Text = "Done"; What we all now from WinForms Chapter 1 class 101, is the form won't display changes to the user until after the Entire Function completes... meaning the "Loading" message will never be displayed to the user. The following code is needed. Form1.SuspendLayout(); StatusBarMessageText.Text = "Loading

Background worker - report progress with string array

北战南征 提交于 2019-11-27 18:17:17
问题 I need to return multiple STRING values from my backgroundworker in each loop, so I tried to use ReportProgress second parameter as string array. Example of code: private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { string[] workerResult = new string[2]; for (int i=0; i<someNumber; i++) { //do some heavy calculating workerResult[0] = "this string"; workerResult[1] = "some other string"; backgroundWorker1.ReportProgress(i, workerResult) // also tried workerResult[] and [2]

Why BackgroundWorker always is busy?

丶灬走出姿态 提交于 2019-11-27 16:38:50
问题 I realized something strange in my background worker in my WPF application. What I'm trying to accomplish right now is to wait until the BW finishes to start another thread. Check the following code: if (bw.IsBusy) { bw.CancelAsync(); System.Threading.ThreadStart WaitThread = new System.Threading.ThreadStart(delegate() { while (bw.IsBusy) { System.Threading.Thread.Sleep(100); } bw.RunWorkerAsync(); }); System.Windows.Application.Current.Dispatcher.Invoke( System.Windows.Threading

Get File Size on FTP Server and put it on a Label

老子叫甜甜 提交于 2019-11-27 16:23:50
I'm trying to get the size of a file that is hosted on a FTP Server and put it in a Label while the `BackgroundWorker works in the background. I'm using " Try " to get the value, however the value is caught on the first attempt. After downloading, if I press to try to get it again then it works. Note : The progress bar also does not work on the first try. Image What I have tried: Private Sub BWorkerD_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BWorkerD.DoWork Dim buffer(1023) As Byte Dim bytesIn As Integer Dim totalBytesIn As Integer Dim output As IO.Stream Dim

Progress Bar and Background Worker

为君一笑 提交于 2019-11-27 15:19:19
I have a progress bar and backgroundworker in VB.Net that I would want to work in a different form as given below: Form1() { MaxRows = 10 for i = 0 to MaxRows then // Update my value on the progressbar .... next } ProgressBarForm Private Sub ProgressBarForm_Shown(sender As Object, e As EventArgs) Handles Me.Shown TransferProgressBar.Visible = True ProgressBarBackgroundWorker.RunWorkerAsync() End Sub Private Sub ProgressBarBackgroundWorker_DoWork(sender As Object, e As ComponentModel.DoWorkEventArgs) Handles ProgressBarBackgroundWorker.DoWork For i = 0 To TransferProgressBar.Maximum 'Dim

Basic BackgroundWorker usage with parameters

谁都会走 提交于 2019-11-27 13:53:41
问题 My process intensive method call that I want to perform in a background thread looks like this: object.Method(paramObj, paramObj2); All three of these objects are ones I have created. Now, from the initial examples I have seen, you can pass an object into a backgroundworker's DoWork method. But how should I go about doing this if I need to pass additional parameters to that object, like I'm doing here? I could wrap this in a single object and be done with it, but I thought it would be smart

Thread/threadpool or backgroundworker

蓝咒 提交于 2019-11-27 13:49:18
I would like to know what to use for tasks that need alot of performance. Backgroundworker , Thread or ThreadPool ? I've been working with Threads so far, but I need to improve speed of my applications. BackgroundWorker is the same thing as a thread pool thread. It adds the ability to run events on the UI thread. Very useful to show progress and to update the UI with the result. So its typical usage is to prevent the UI from freezing when works needs to be done. Performance is not the first goal, running code asynchronously is. This pattern is also ably extended in later .NET versions by the