backgroundworker

BackgroundWorker report progress from external Class?

不想你离开。 提交于 2019-12-05 00:59:32
问题 I have a working solution that reports progress & text to a progress bar and a label on the applications's main form. I have now moved my worker methods to a class to they are accessible across multiple forms etc. Within the worker methods are BW.ReportProgress() statements that push back the progress and text to the BackgroundWorker in the main form. To give a better idea here is the file layout: MainScreen.cs List repSelected = new List(); XMLandRar xXMLandRar = new XMLandRar(); private

Is thread-local storage persisted between backgroundworker invocations?

こ雲淡風輕ζ 提交于 2019-12-05 00:16:24
Are backgroundworker threads re-used? Specifically, if I set a named data slot (thread-local storage) during the DoWork() method of a backgroundworker, will the value of that data slot persist, potentially to be found be some other thread at a later time? I wouldn't have thought so, but I have this bug... EDIT: This blog post suggests that BackGroundWorker utilises a ThreadPool , which implies that Threads are re-used. So the question becomes; do re-used threads potentially persist thread-local storage between invocations? When the thread pool reuses a thread, it does not clear the data in

How do you set the UserState in the RunWorkerCompletedEventArgs object?

房东的猫 提交于 2019-12-05 00:03:33
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 object as it's finishing. Any ideas? snippet from my WorkManager.cs class public Worker AddWorker() {

WPF : Is it impossible to UI load in background thread?

久未见 提交于 2019-12-04 22:17:55
问题 I've making a some application which build a huge-sized FlowDocument. The elapsed time of building FlowDocument was about 3~4 seconds. So I like to building FlowDocument in BackgroundWorker, not UI thread. but BackgroundWorker can't return WPF UI object. (It occured InvalidOperationException exception.) how can i solve this problem? 回答1: If you want to build a FlowDocument in another thread, it has to be a second UI-type thread, not a BackgroundWorker. In spite of what the documentation says,

In MVVM, how can I prevent BackgroundWorker from freezing UI?

淺唱寂寞╮ 提交于 2019-12-04 21:00:57
First of all, I've seen many similar issues here on SO and around the net. None of these appear to address my particular issue. I have a simple BackgroundWorker whose job is to read a file line-by-line and report progress to indicate how far through it is. There are up to a total of 65,553 lines in the file, so it is important to me that the BackgroundWorker finishes as fast as possible. Since MVVM is built on separation of concerns (SoC) and the decoupling of the View and View-Model, the BackgroundWorker updates properties on the View-Model that the View binds to. My setup is very similar to

Is this thread/background worker design for a C# WPF application OK?

a 夏天 提交于 2019-12-04 19:47:41
Being new to using threads etc in UI's, can I ask is the following simple design seem OK. Refer to diagram image at link here In particular: a) use of backgroundworker & backgroundworker ProgressChanged to have the aggregator work on a separate thread. So I would need a custom class/type that had all the data I'd need to pass back from the aggregator thread to the UI thread I assume. b) create a separate thread within the aggregator to ensure that the SharpPCap/WinPCap callback method is in a different thread. So this Capture Manager thread writes packet results to a shared Buffer. I'm

BackgroundWorker still freezes UI

只谈情不闲聊 提交于 2019-12-04 19:20:58
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 = new Stack<string>(20); dirs.Push(e.Argument.ToString()); while (dirs.Count > 0) { string currentDir

Updating an Image UI property from a BackgroundWorker thread

北城余情 提交于 2019-12-04 17:45:05
In a WPF application I'm writing, I have a TransformedBitmap property which is bound to an Image object on the UI. Whenever I change this property, the Image is updated (and thus the image being displayed to the screen is updated). In order to prevent the UI from freezing or becoming unresponsive whilst I retrieve the next image, I'm attempting to the snapshot retrieval with a BackgroundWorker like this: private void bw_DoWork(object sender, DoWorkEventArgs e) { e.Result = this.snapshotHelper.GetSnapshot(ImageFormat.Bmp); } then, in my RunWorkerCompleted method, I have the following: private

autoscroll to bottom of multiline textbox being updated by backgroundworker

て烟熏妆下的殇ゞ 提交于 2019-12-04 16:25:20
问题 I have a background worker control that is set to perform a task, and update a multiline text box on my main UI using a delegate procedure. this is all working perfectly, however once the updating scrolls off the bottom of the text box, the scroll bars appear, but the continuous refreshing causes the text box to stay locked at the top. Ideally, I would like the text box to auto-scroll itself to the bottom to show the latest entry in real-time. What would be the best way to implement this? I

Update progressbar from a backgroundworker in WPF

扶醉桌前 提交于 2019-12-04 13:52:08
I'm trying to make a progressbar advance using a BackgroundWorker . The final goal is to show the progress of a background search, but I first want to get to know the progress bar by doing a simple simulation. This is the code: public MainWindow() { InitializeComponent(); worker = new BackgroundWorker(); // variable declared in the class worker.WorkerReportsProgress = true; worker.DoWork += new DoWorkEventHandler(worker_DoWork); worker.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged); worker.RunWorkerCompleted += worker_RunWorkerCompleted; } private void