backgroundworker

WPF MVVM updating the View Model on a Background Worker

烈酒焚心 提交于 2019-12-05 04:42:42
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 BackgroundWorker. This would be done in the RunWorkerCompleted event. But does this lock the UI thread and

C# / VB.Net Task vs Thread vs BackgroundWorker

拜拜、爱过 提交于 2019-12-05 04:28:37
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 string and update the UI. If I use "HttpWebRequest.BeginGetResponse" to wait for the async result and

When to use BackgroundWorker or Manage threads on your own? [duplicate]

假如想象 提交于 2019-12-05 04:18:32
Possible Duplicate: BackgroundWorker vs background Thread When should I consider managing threads on my own as opposed to using the BackgroundWorker? I know managing threads on your own can be difficult and can lead to problems, is there a direct benefit of managing them on your own? DevExpress Team You will find an answer to this question at: BackgroundWorker vs background Thread 来源: https://stackoverflow.com/questions/5195733/when-to-use-backgroundworker-or-manage-threads-on-your-own

using backgroundworker in Winforms (C#) with MVP pattern

自闭症网瘾萝莉.ら 提交于 2019-12-05 03:16:13
问题 I've been trying to refactor a spaghetti code of an app by using MVP pattern. But now I'm struggling with this: A form that has button that calls a the DoWork method (of a backgroundworker) which is a long operation. My question is if I move the long operation out of the view into the Presenter then how do I send progress changes from this operation to the View? The BGW must be in the Presenter also? Can you give me a sample of how to do this? Thank you in advance. 回答1: This outlines the use

Execute a method in main thread from event handler

倖福魔咒の 提交于 2019-12-05 03:06:26
I have a custom Queue class inherited from Queue class. It has an event ItemAdded. In the event handler of this event i am executing a method. But it is running other than main thread, though i want it in main thread. I don't know how to do it. Any suggestion ? //My custom class using System; using System.Collections; //Required to inherit non-generic Queue class. namespace QueueWithEvent { public class SmartQueue:Queue { public delegate void ItemAddedEventHandler(object sender, EventArgs e); public event ItemAddedEventHandler ItemAdded; protected virtual void OnItemAdded(EventArgs e) { if

Changing the property of a control from a BackgroundWorker C#

泪湿孤枕 提交于 2019-12-05 02:36:48
问题 I'm trying to load a bunch of files from a directory, and while it's loading, display a progress bar status, as well as a label that displays which file is being processed. private void FileWorker_DoWork(object sender, DoWorkEventArgs e) { for (int i = 0; i < Files.Length; i++) { Library.AddSong(Files[i]); FileWorker.ReportProgress(i); } } At the moment it processes everything properly, and the progress bar displays status properly, but when i try to change the label's text (lblfile.text) it

which thread does backgroundworker completed event handler run on?

本小妞迷上赌 提交于 2019-12-05 02:03:09
I have a GUI application that needs to run long calculations (think a minute or more) and the way that it deals with this is by giving the calculation to a background worker. (this part is fine) The question I have is if I do something like: this.backgroundWorker.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.doSomethingElse); is doSomethingElse going to be run on the main UI thread or whatever in the thread pool the background worker ran on? thank for any help you can provide. It's going to be run in the same thread that BackgroundWorker is in, ie most

File.Exists() returns false, but not in debug

旧巷老猫 提交于 2019-12-05 01:34:24
问题 I'm being completely confused here folks, My code throws an exception because File.Exists() returns false public override sealed TCargo ReadFile(string fileName) { if (!File.Exists(fileName)) { throw new ArgumentException("Provided file name does not exist", "fileName"); } Visual studio breaks at the throw statement, and I immediately check the value of File.Exists(fileName) in the immediate window. It returns true . When I drag the breakpoint back up to the if statement and execute it again,

TwainDotNet Scanning using TWAIN with BackgroundWorker

╄→尐↘猪︶ㄣ 提交于 2019-12-05 01:18:14
问题 Has anyone tried TwainDotNet for scanning with TWAIN API calls from .NET? Though it works well usually I've some issues with it when used along with WPF application using MVVM. Basically I'm calling Twain scanning functions from a Service, which in turn uses a BackgroundWorker. List<BitmapSource> bitmapSources = new List<BitmapSource>(); Twain twain = new Twain(new WpfWindowMessageHook(_window)); ScanSettings settings = new ScanSettings() { ShowTwainUI = false }; using (BackgroundWorker

cancel background worker exception in e.result

霸气de小男生 提交于 2019-12-05 01:12:29
问题 i have a serious problem with background worker. code is working if task is ending regular. when i cancel the background task i get an system.invalidoperationexception in the RunWorkerCompleted function for e.Result. what is wrong? thank you. here is my cod: private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { if (backgroundWorker.CancellationPending == true) e.Cancel = true; e.Result = resultList; } private void backgroundWorker1_RunWorkerCompleted(object sender,