backgroundworker

Cancelling a BackgroundWorker

…衆ロ難τιáo~ 提交于 2019-11-28 12:14:07
问题 My DoWork for backgroundworker1 sets a wait timer via a class WakeUp , it works well. The problem right now is that sometimes my while CancellationPending is ending in an infinite loop. So inside DoWork there is a call to WaitOne , the DoWork sets the wait timer stuff and waits the thread until the timer triggers. I need for the BackgroundWorker to shut down right away but as well I have to keep a reference to BackgroundWorker so I can keep track of each alarm in my program. Why is

c# winform background worker and progress bar

血红的双手。 提交于 2019-11-28 11:45:36
问题 I am trying to get the progress bar to increment using a BG Worker. I am currently using 2 BG workers, one to add data into a DB and one for the progress bar. The DB upload is working fine, yet the progress bar is not. Code: BackgroundWorker bg2 = new BackgroundWorker(); bg2.DoWork +=new DoWorkEventHandler(bg2_DoWork); bg2.RunWorkerAsync(); void bg2_DoWork(object sender, DoWorkEventArgs e) { while (bg1.IsBusy) DrawWellPlate.pbar.Increment(1) } bg1 that it refers to is the database upload

Displaying a progressbar while executing an SQL Query

前提是你 提交于 2019-11-28 11:02:21
I want to inform the user while data is being read from an SQL database and I decided to create a form with a progressbar but it doesn't work - maybe because a thread is needed. I want to create the form programmatically ProgressBar pb = new ProgressBar(); pb.MarqueeAnimationSpeed = 30; pb.Style = ProgressBarStyle.Marquee; pb.Dock = DockStyle.Fill; progressForm.ClientSize = new Size(200, 50); progressForm.FormBorderStyle = FormBorderStyle.FixedDialog; progressForm.StartPosition = FormStartPosition.CenterScreen; progressForm.Controls.Add(pb); progressForm.ControlBox = false; progressForm

BackgroundWorker OnWorkCompleted throws cross-thread exception

送分小仙女□ 提交于 2019-11-28 10:32:10
I have a simple UserControl for database paging, that uses a controller to perform the actual DAL calls. I use a BackgroundWorker to perform the heavy lifting, and on the OnWorkCompleted event I re-enable some buttons, change a TextBox.Text property and raise an event for the parent form. Form A holds my UserControl. When I click on some button that opens form B, even if I don't do anything "there" and just close it, and try to bring in the next page from my database, the OnWorkCompleted gets called on the worker thread (and not my Main thread), and throws a cross-thread exception. At the

c# backgroundworker won't work with the code I want it to do

≯℡__Kan透↙ 提交于 2019-11-28 10:10:14
问题 my code brings up no errors when compelling i just get one while trying to run it. it says ThreadStateException was unhanded by the user code i have searched for this in multiple places and all my code looks to work in the same way i have know idea what the problem is. here is the code that isnt working private void button1_Click(object sender, EventArgs e) { backgroundWorker1.RunWorkerAsync(); } private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { FolderBrowserDialog

VB.NET Delegates and Invoke - can somebody explain these to me?

断了今生、忘了曾经 提交于 2019-11-28 07:49:39
I'm new to the world of threading, but a few aspects of an app I'm working on require me to use a BackgroundWorker control to prevent the UI freezing up while it's doing some file operations. What I'm trying to do is update a couple of form labels from within the BackgroundWorker. Having never worked with this before I very quickly discovered that I can't access controls that weren't created within the same thread, so after a bit of research I've implemented the following code that seems to make everything work: Private Delegate Sub DelegateUpdateStatus(ByVal statusText As String, ByRef

Simple BackgroundWorker is not updating label on web page

随声附和 提交于 2019-11-28 07:13:34
问题 I have used a piece of simple code from this helpful post It uses a button and a label, the label should report "10% completed"... "20% completed"... and so on. When I debug, the code is getting hit, but my label is not updating on the browser. I have tried with & without update panels, with and without a masterpage. protected void btnStartThread_Click(object sender, EventArgs e) { BackgroundWorker bw = new BackgroundWorker(); // this allows our worker to report progress during work bw

How to dynamically create a background worker in VB.net

北城以北 提交于 2019-11-28 07:11:10
问题 I have a VB.net project which uses a background worker to do some stuff. Now I want to expand the project to be able to do multiple stuff :) A user can enter an URL in a textbox and when the user click on the parse button the program creates a new tabcontrol a outputs some data. I use a hardcoded background worker for this. But now I want to run multiple background workers to do this stuff so I can't rely on hard coding the background worker(s). Is it possible to create background workers

How do I update a Label from within a BackgroundWorker thread?

吃可爱长大的小学妹 提交于 2019-11-28 06:27:47
问题 When I used WinForms, I would have done this in my bg_DoWork method: status.Invoke(new Action(() => { status.Content = e.ToString(); })); status.Invoke(new Action(() => { status.Refresh(); })); However in my WPF application I get an error saying that Invoke does not exist for Label . Any help would be appreciated. 回答1: This will help you. To Execute synchronously: Application.Current.Dispatcher.Invoke(new Action(() => { status.Content = e.ToString(); })) To Execute Asynchronously: Application

WPF/C# Don't block the UI

ぐ巨炮叔叔 提交于 2019-11-28 05:40:41
问题 I've an existing WPF application, which has several sections. Every section is a UserControl, that implements an interface. The interface specify two methods: void LoadData([...]) and bool UnloadData() . Those method are called by the UI thread, so we need to do our work in backgroundworker if it's time consuming. No problems with LoadData since we can update the UI asynchronously. The problem is with UnloadData(). This should return if we can really leave the current view. This is computed