backgroundworker

Access windows control from Backgroundworker DoWork

青春壹個敷衍的年華 提交于 2019-12-30 11:27:06
问题 my issue is the following: I have a windows form in which I've placed a LayoutPanel, when the forms Loads, multiple controls like: textboxes and labels are being added to the LayoutPanel. Then on a button click, I need to process the data entered by the user on those dynamically created controls. For that purpouse I use a Backgroundworker which is supposed to take those controls and read their data. My issue es that the Backgroundworker doesn't allows me to access the control from the DoWork

How to directly access the UI thread from the BackgroundWorker thread in WPF?

。_饼干妹妹 提交于 2019-12-30 11:09:24
问题 I'm creating a backup utility in WPF and have a general question about threading : In the method backgroundWorker.DoWork() , the statement Message2.Text = "..." gives the error " The calling thread cannot access this object because a different thread owns it. ". Is there no way for me to directly access the UI thread within backgroundWorker.DoWork(), i.e. change text in a XAML TextBox at that point? Or do I need to store all display information in an internal variable , and then display it in

How to send more arguments in C# backgroundworker progressed changed event

≡放荡痞女 提交于 2019-12-30 03:10:49
问题 I understand how we can pass one variable(progresspercentage) to "progresschanged" function , like so. backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged); ... worker.ReportProgress(pc); ... private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e) { this.progressBar1.Value = e.ProgressPercentage; } But I want to pass more variables to this function, some thing like: worker.ReportProgress(pc,username,score); .

Cannot use a DependencyObject that belongs to a different thread than its parent Freezable

泪湿孤枕 提交于 2019-12-29 08:53:06
问题 WPF - I'm using BackgroundWorker to create a Model3D object, but when I want to add it to a Model3DGroup that is defined in the XAML, I get exception: Cannot use a DependencyObject that belongs to a different thread than its parent Freezable. This is the whole code behind: public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += bw_DoWork; bw.RunWorkerCompleted += bw_RunWorkerCompleted; bw.RunWorkerAsync

Spawn Multiple Threads for work then wait until all finished

狂风中的少年 提交于 2019-12-27 16:29:29
问题 just want some advice on "best practice" regarding multi-threading tasks. as an example, we have a C# application that upon startup reads data from various "type" table in our database and stores the information in a collection which we pass around the application. this prevents us from hitting the database each time this information is required. at the moment the application is reading data from 10 tables synchronously. i would really like to have the application read from each table in a

Spawn Multiple Threads for work then wait until all finished

穿精又带淫゛_ 提交于 2019-12-27 16:26:28
问题 just want some advice on "best practice" regarding multi-threading tasks. as an example, we have a C# application that upon startup reads data from various "type" table in our database and stores the information in a collection which we pass around the application. this prevents us from hitting the database each time this information is required. at the moment the application is reading data from 10 tables synchronously. i would really like to have the application read from each table in a

Unhandled exceptions in BackgroundWorker

╄→гoц情女王★ 提交于 2019-12-27 12:15:09
问题 I have a small WinForms app that utilizes a BackgroundWorker object to perform a long-running operation. The background operation throws occasional exceptions, typically when somebody has a file open that is being recreated. Regardless of whether the code is run from the IDE or not .NET pops up an error dialog informing the user that an Unhandled exception has occurred. Compiling the code using the Release configuration doesn't change this either. According to MSDN: If the operation raises an

Invalid cross thread access backgroundworker error c#

筅森魡賤 提交于 2019-12-25 17:45:20
问题 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.OleDb; using System.Threading; namespace SRS { public partial class excelimport : Form { public excelimport() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { OpenFileDialog openfiledialog1 = new OpenFileDialog(); if (openfiledialog1.ShowDialog() == System

C# W10 UWP BackgroundTask StorageFile

左心房为你撑大大i 提交于 2019-12-25 14:05:08
问题 I'm trying to set an image to lockscreen or wallpaper in my C# W10 UWP app in a BackgroundTask ... I can do this just fine in normal execution, but when I put the same code into a BackgroundTask , the code hangs at StorageFile.CreateStreamedFileFromUriAsync . // See if file exists already, if so, use it, else download it StorageFile file = null; try { file = await ApplicationData.Current.LocalFolder.GetFileAsync(name); } catch (FileNotFoundException) { if (file == null) { Debug.WriteLine(

Rendering and loading fonts into the FontCache on a background thread?

不想你离开。 提交于 2019-12-25 14:02:20
问题 I am trying to show a Font picker list similar to the one in Blend: Blend Font Picker http://img691.imageshack.us/img691/60/blendfontpicker.png Like Blend, I am seeing performance issues when the FontFamilies are not loaded in the FontCache. It seems that the penalty I am paying is the time it takes to actually render the FontFamily for the given FontSize and save it into the FontCache. Once the rendered font is in the cache the problem goes away. I have tried iterating the Fonts