backgroundworker

BackgroundWorker Not working in VSTO

本小妞迷上赌 提交于 2019-11-30 13:26:57
问题 I have a background worker. Before I invoke the worker I disable a button and make a gif visible. I then invoke the runworkerasync method and it runs fine until comleteion. On the 'RunWorkerCompleted()' I get a cross thread error. Any idea why? private void buttonRun_Click(object sender, EventArgs e) { if (comboBoxFiscalYear.SelectedIndex != -1 && !string.IsNullOrEmpty(textBoxFolderLoc.Text)) { try { u = new UpdateDispositionReports( Convert.ToInt32(comboBoxFiscalYear.SelectedItem.ToString())

Popping a MessageBox for the main app with Backgroundworker in WPF

假装没事ソ 提交于 2019-11-30 13:06:17
In a WPF app, I am using a BackgroundWorker to periodically check for a condition on the server. While that works fine, I want to pop a MessageBox notifing the users if something fails during the check. Here's what I have: public static void StartWorker() { worker = new BackgroundWorker(); worker.DoWork += DoSomeWork; worker.RunWorkerAsync(); } private static void DoSomeWork(object sender, DoWorkEventArgs e) { while (!worker.CancellationPending) { Thread.Sleep(5000); var isOkay = CheckCondition(); if(!isOkay) MessageBox.Show("I should block the main window"); } } But this MessageBox does not

What does Cannot modify the logical children for this node at this time because a tree walk is in progress mean?

痴心易碎 提交于 2019-11-30 13:00:03
问题 I am setting the DataContext of an object in the completed method of a background worker thread. For some reason, I get an error saying: Cannot modify the logical children for this node at this time because a tree walk is in progress pointing to the Chart1.DataContext=allDates line. What does a tree walk is in progress mean? I've tried doing this set using a Dispatcher operation as well and that gives the same error... Any ideas? Google yeilds nothing on this error message. The code taht's

How to wait for BackgroundWorker to finish and then exit console application

喜欢而已 提交于 2019-11-30 11:33:47
I have written a sample console application to test backgroundworker using one of the examples posted here in Stackoverflow. I have a backgroundworker which start with the main method but its ending in the middle of the operation if I press enter because I have written a console.readkey in the main method. But I want it to wait till the backgroundworker has finished doing the job then exit the application. This is my code. class Program { private static BackgroundWorker worker = new BackgroundWorker(); private event EventHandler BackgroundWorkFinished; static void Main(string[] args) { worker

WinForms UI responsiveness when dealing with “heavy” data

谁说我不能喝 提交于 2019-11-30 10:01:46
I'm modifying a windows form to allow data to be loaded in the background while the UI remains responsive. The data takes noticeable time to both retrieve and bind. Ideally, I would do both in the background, but there is some ambiguity about what kind of UI updates I should be doing in the background (as in outside the main thread). A solid example that shows data retrieval and data binding in the background would be very helpful. The retrieval can, and should, be pushed off to a background thread--but there's some patterns to put it all in place. Basically you'll start a background thread to

Background worker proper way to access UI

自作多情 提交于 2019-11-30 09:45:04
I'm not sure if I'm doing this correctly, but I have the following code that I am using (click button1, do the _DoWork). The question is this: how do I call the UI to get the values of textbox1 and textbox2 as they cannot be called as they are on a different thread. Should I be using dispatchers? private void button1_Click(object sender, RoutedEventArgs e) { if (textBox1.Text == "") { MessageBox.Show("Please enter a username and password", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); } else { bw.DoWork += new DoWorkEventHandler(bw_DoWork); bw.RunWorkerAsync(); } } private void bw

Background worker exception handling

余生颓废 提交于 2019-11-30 09:00:56
问题 I am slightly confused on how to deal with an exception. I have a background worker thread that runs some long running process. My understanding is if an exception occurs on the background worker thread the code will still end up at the RunWorkerCompleted method. void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (e.Error != null) throw e.Error; If this is the case is there any point in putting a try catch block around the bgWorker.RunWorkerAsync(); call, I

How to test a ViewModel that loads with a BackgroundWorker?

余生长醉 提交于 2019-11-30 08:51:53
One of the nice things about MVVM is the testability of the ViewModel. In my particular case, I have a VM that loads some data when a command is called, and its corresponding test: public class MyViewModel { public DelegateCommand LoadDataCommand { get; set; } private List<Data> myData; public List<Data> MyData { get { return myData; } set { myData = value; RaisePropertyChanged(() => MyData); } } public MyViewModel() { LoadDataCommand = new DelegateCommand(OnLoadData); } private void OnLoadData() { // loads data over wcf or db or whatever. doesn't matter from where... MyData = wcfClient

Best ASP.NET Background Service Implementation

只愿长相守 提交于 2019-11-30 07:51:36
问题 What's the best implementation for more than one background service in an ASP.NET application? Timer Callback Timer timer = new Timer(new TimerCallback(MyWorkCallback), HttpContext, 5000, 5000); Thread or ThreadPool Thread thread = new Thread(Work); thread.IsBackground = true; thread.Start(); BackgroundWorker BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += new DoWorkEventHandler(DoMyWork); worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(DoMyWork_Completed);

BackgroundWorker Not working in VSTO

风格不统一 提交于 2019-11-30 07:08:08
I have a background worker. Before I invoke the worker I disable a button and make a gif visible. I then invoke the runworkerasync method and it runs fine until comleteion. On the 'RunWorkerCompleted()' I get a cross thread error. Any idea why? private void buttonRun_Click(object sender, EventArgs e) { if (comboBoxFiscalYear.SelectedIndex != -1 && !string.IsNullOrEmpty(textBoxFolderLoc.Text)) { try { u = new UpdateDispositionReports( Convert.ToInt32(comboBoxFiscalYear.SelectedItem.ToString()) , textBoxFolderLoc.Text , Properties.Settings.Default.TemplatePath , Properties.Settings.Default