backgroundworker

How do you set the UserState in the RunWorkerCompletedEventArgs object?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-10 01:10:04
问题 HI all. I have an array of BackgroundWorker objects running instances of a Worker class. When I call the Worker class the object instance does it's thing and then runs out of code (the loop finishes). I'm able to listen to the RunWorkerCompleted() event but when it calls the delegate that I've set up I need to know which of my Worker objects just completed. I see a UserState property in the RunWorkerCompletedEventArgs that comes to my delegate but I have no idea how to set this in my Worker

BackgroundWorker still freezes UI

你说的曾经没有我的故事 提交于 2019-12-10 00:03:25
问题 I've got the following code, As you can see the background worker searches for files and in the progress changed event files are added to a listview, however since there is lots of files being added to the listview, the UI becomes unresponsive, I could Sleep the thread in the loops but I don't think that's a good practice, what's the best way to prevent the UI freeze? to elaborate more, listview is a form control on a form. void bg_DoWork(object sender, DoWorkEventArgs e) { Stack<string> dirs

VB.net stopping a backgroundworker

烂漫一生 提交于 2019-12-09 12:52:11
问题 I want to create a button that could stop my background worker and end all the process it is working on. Here is my sample backgroundworker code: Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Try If BackgroundWorker1.IsBusy <> True Then BackgroundWorker1.RunWorkerAsync() End If Catch ex As Exception End Try End Sub Private Sub BackgroundWorker1_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork Dim

BackgroundWorker and Threads

落爺英雄遲暮 提交于 2019-12-09 10:13:48
问题 What are the pros and cons in using the either for achieving a given task. The million dollar question is which one to use and when? Many Thanks. 回答1: I use to associate BackgroundWorker as a wrapper for what Threads would do. So I use BackgroundWorker on GUI works, and Threads on more specialized or dirty jobs (Windows Services, etc) 回答2: If by "Threads" you mean explicitly using the System.Threading.Thread class to create, configure and kick off your own threads, then the answer is that

Right way of using Backgroundworker

纵然是瞬间 提交于 2019-12-08 19:24:26
I'm using a backgroundworker for showing a loadingscreen. The DO-event looks as follow: private void bwLoadingScreen_DoWork(object sender, DoWorkEventArgs e) { _ls = new LoadingScreen(); _ls.Show(); while (!bwLoadingScreen.CancellationPending) { Application.DoEvents(); } } I use the following code to Dispose the Loadingscreen: if (_ls.InvokeRequired && !_ls.IsDisposed) { Invoke(new MethodInvoker(delegate { _ls.Close(); _ls.Dispose(); })); } else if (!_ls.IsDisposed) { _ls.Hide(); _ls.Dispose(); } Should I use the RunWorkerCompleted event for this? Is this the right way to use the

Constantly monitor processes

泪湿孤枕 提交于 2019-12-08 15:07:09
问题 I've written some code which monitors the running windows processes. I wish to know when a certain process starts and when it ends. The code works just like I want it to. Now, I wish to implement it in a windows form server application - so it will run in loop as long as the form is alive. I guess I should make it run asynchronously maybe using a BackgroundWorker . I'm just not sure what's the best way to do it and how. Here is my monitor code: using System; using System.Management; using

Performing long running UI changes without blocking the main thread

无人久伴 提交于 2019-12-08 13:22:11
问题 Is there anyway to run a large number of UI updates without effecting the main thread in a C# winforms application? I would like to avoid a long delay when a user clicks a specific event (which in my case is many close form calls to dispose of memory) I know i can use BackgroundWorker to perform lengthy operations in the "do work" event, but the problem is that you cant change any UI in this event (it will cause a cross thread exception) - so i cant put my large number of close form calls

Differences of Delegates vs BackgroundWorker?

房东的猫 提交于 2019-12-08 12:45:59
问题 Can anyone explain the difference between Delegates and BackgroundWorker?In which case Backgroundworker is more efficient than Delegate?Since we are having asynchronous delegate what is the need to use BackGroungWorker. 回答1: BackgroundWorker: The BackgroundWorker class allows you to run an operation on a separate, dedicated thread. Delegate: A delegate is a type that defines a method signature. ... Delegates are used to pass methods as arguments to other methods. The question of which one to

C# - Populating Panel with controls from BackgroundWorker

社会主义新天地 提交于 2019-12-08 11:44:53
问题 So I am writing a small Twitter client for me to use. I am using a combination of one big panel, with smaller panels representing the individual tweets. In each smaller panel, I have a PictureBox and a RichTextBox. Now, my problem is that loading more than 10 tweets causes a slowdown because I am dynamically generating the panels. So I decided to do this using a BackgroundWorker and then add those panels to the main panel. I've done this numerous times with writing text to a textbox from a

Pause a BackgroundWorker for n-seconds

陌路散爱 提交于 2019-12-08 10:42:44
问题 I was feeling nostalgic and have developed a text based Adventure Game Creator IDE, which has a Windows Form that displays messages to a rich text box. I have written a message dispatcher class that will send text (room descriptions and messages) from a stream to the text box using a BackgroundWorker. This works brilliantly, but I am having a small problem... I need to do is be able to pause/hold the Background worker for any number of seconds of my choosing. The reason for this is that, in