backgroundworker

How to update the progress bar through Backgroundworker in C#? [duplicate]

可紊 提交于 2019-12-13 09:59:12
问题 This question already has answers here : c# winform background worker and progress bar (2 answers) Closed 6 years ago . I have a Backgrounder worker which generates the Excel file through the C# function GenerateExcel() . Within the GenerateExcel() function, I am using the progressbar to update the status. However, it is throwing an exception, that I cannot modify the GUI control. Any idea what could be the error in the code ? BackgroundWorker backgroundWorker1 = new BackgroundWorker();

DotNetZip in BackgroundWorker update progressbar and label on a form

落花浮王杯 提交于 2019-12-13 07:46:57
问题 I'm creating option to backup data of my app with DotNetZip and to avoid freezing the app I've found that the best way for a this type of action best way is to use BackgroundWorker. So I came with something like this: private void processButton_Click(object sender, EventArgs e) { BackgroundWorker worker = new BackgroundWorker(); worker.WorkerReportsProgress = true; worker.DoWork += new DoWorkEventHandler(worker_DoWork); worker.ProgressChanged += new ProgressChangedEventHandler(worker

BackgroundWorker hide form window upon completion

為{幸葍}努か 提交于 2019-12-13 07:34:54
问题 I'm having some trouble with hiding a form when a BackgroundWorker process is completed. private void submitButton_Click(object sender, EventArgs e) { processing f2 = new processing(); f2.MdiParent = this.ParentForm; f2.StartPosition = FormStartPosition.CenterScreen; f2.Show(); this.Hide(); backgroundWorker1.RunWorkerAsync(); } private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { // loop through and upload our sound bits string[] files = System.IO.Directory.GetFiles

Cross-thread operation not valid - Need to use and update controls on UI thread from async thread

五迷三道 提交于 2019-12-13 06:50:16
问题 I have a program that builds report documents and am wanting to place the routine to build the report under a "DoWork" handler for a background worker. The initial part of the report is started, however, once I reference selected items in a combo box it stops executing? Here is my code: Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click ProgressBar1.Visible = True Application.EnableVisualStyles() ProgressBar1.Style = ProgressBarStyle.Marquee ProgressBar1

C# WinForms populating TreeView from List<myObj>

送分小仙女□ 提交于 2019-12-13 04:40:07
问题 I have this structure of classes: public class L3Message { public int Number { get; set; } public string MessageName { get; set; } public string Device { get; set; } public string Time { get; set; } public string ScramblingCode { get; set; } public List<Parameter> Parameters { get; set; } public L3Message() { Parameters = new List<Parameter>(); } } public class Parameter { public int numOfWhitespaces { get; set; } public string ParameterName { get; set; } public string ParameterValue { get;

c# pass parameter to Action

六眼飞鱼酱① 提交于 2019-12-13 03:16:16
问题 I have the following code: public partial class WaitScreen : Form { public Action Worker { get; set; } public WaitScreen(Action worker) { InitializeComponent(); if (worker == null) throw new ArgumentNullException(); Worker = worker; } protected override void OnLoad(EventArgs e) { base.OnLoad(e); Task.Factory.StartNew(Worker).ContinueWith(t => { this.Close(); }, TaskScheduler.FromCurrentSynchronizationContext()); } } And this is the code in the consumer: private void someButton_Click(object

Images downloaded in a async method shown after coming back from a detail page, so actually updating the UI after a background task

别等时光非礼了梦想. 提交于 2019-12-13 03:02:33
问题 I have a ListView with some stuff in and that List has some images that I load in a background task. But when I login and see the LIstview the images are not shown if I go to a detail page from one of my ListViewItems and come back the images are shown. This is my "async" task: private async void DownloadImage(ImageObject imageObject) { ImageByte = await _IDataService.GetImage(imageObject.Id); ImageObjectImageSource = await LoadImageAsync(ImageByte); imageObject.ImageObjectSource =

Update GUI from background worker or event

纵然是瞬间 提交于 2019-12-13 02:57:31
问题 I want to understand how I can update my GUI with a simple text string on a regular basis. Essentially, I'm writing a twitter application which regularly polls twitter for updates. I want the contents of the update to be shown in a text block, one by one on a constant loop. In order to keep the GUI responsive I need to perform the query in a background worker thread, however updating the GUI from this thread is not possible. As a learner, I'm struggling implement a way of updating the GUI by

Background worker report string from a method

♀尐吖头ヾ 提交于 2019-12-13 02:52:38
问题 I've created a copy file method that i would like to wrap around a background worker. I would like the copy file method to report a string back to the UI thread (change a label) on the current file name its on. I can't seem to get it to work and i'm getting cross thread ui errors. Here is my code. Do Work //Textbox Array Values // 0 = computername // 1 = username // 2 = password string[] tbvalues = (string[])e.Argument; string computer = tbvalues[0]; string user = tbvalues[1]; string pass =

Implement multiple timers in C#

落爺英雄遲暮 提交于 2019-12-13 02:46:34
问题 I'm working on a windows forms app where I have several so called "services" that poll data from various services like Twitter, Facebook, Weather, Finance. Now each of my services has its individual polling interval setting so I was thinking I could implement a System.Windows.Forms.Timer for each of my services and set its Interval property accordingly so that each timer would fire an event at the preset interval that will cause the service to pull new data preferably async through a