backgroundworker

Run code in Background Worker

笑着哭i 提交于 2019-12-04 05:06:46
问题 I am trying to work with asp.net. I have very small question. In one of my button click event, I have heavy task that need to be executed and it causing problem. How can i run this code in background worker. Any hint will be appreciated as i have no played with this background worker yet. Here is the code for my background worker. protected void green_button_Click(object sender, EventArgs e) { string stdOut = null; string stdError = null; string address = "192.168.1.88"; string user = "user";

Using BackgroundWorker to complete two methods one after the other WPF/C#

二次信任 提交于 2019-12-04 04:53:43
问题 In my program I have two methods that takes a while to complete, about few minutes each. While these methods are being executed, I display a Progress Bar in a separate window which shows the progress of each method. My two methods are in a static Utility class. They look like the following: public static class Utility { public static bool TimeConsumingMethodOne(object sender) { for (int i = 1; i <= 100; i++) { Thread.Sleep(100); (sender as BackgroundWorker).ReportProgress(i); } return true; }

Update label from mainform class with backgroundworker from another class

回眸只為那壹抹淺笑 提交于 2019-12-04 04:01:02
问题 I have two classes. Public Class MainForm Private Project As clsProject Private Sub btnDo_Click ... Backgroundworker.RunWorkerAsync() End Sub Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork Project = New clsProject End Sub and two methods inside MainForm Public Shared Sub setLabelTxt(ByVal text As String, ByVal lbl As Label) If lbl.InvokeRequired Then lbl.Invoke(New setLabelTxtInvoker

Showing Modal Window while BackgroundWorker runs, without getting STA/MTA issue

泄露秘密 提交于 2019-12-04 03:56:39
问题 I am working on a WPF application. I have a time consuming method that I want to run async via BackgroundWorker . While the method runs, I want to display a modal "Please Wait..." dialog window, which must automatically close when the BackgroundWorker completes. I currently have very little experience with BackgroundWorker or any multi threaded programming. The code below currently results in an InvalidOperationException , with the message "The calling thread must be STA, because many UI

How do I properly cancel and restart a BackgroundWorker process?

99封情书 提交于 2019-12-04 03:34:45
Users of my application type HTML into a TextBox control. I want my application to validate their input in the background. Because I don't want to hammer the validation service, I've tried to build in a one-second delay before each validation. However, I don't seem to be able to correctly interrupt an already-running BackgroundWorker process. My Visual Basic code: Sub W3CValidate(ByVal WholeDocumentText As String) 'stop any already-running validation If ValidationWorker.IsBusy Then ValidationWorker.CancelAsync() 'wait for it to become ready While ValidationWorker.IsBusy 'pause for one

C# Multiple BackgroundWorkers

不打扰是莪最后的温柔 提交于 2019-12-04 03:01:41
问题 I am trying to setup multiple BackgroundWorker s to do work and when not busy start doing the next bit of work. I can't seem to get them working properly. I have the below code. When I set FilesToProcess equal or less than MaxThreads it works perfectly although if I make it higher, the app freezes. I am sure it is something simple, but I just can't see it. using System; using System.ComponentModel; using System.Threading; using System.Windows.Forms; namespace bgwtest { public partial class

Backgroundworker abort

人盡茶涼 提交于 2019-12-04 03:01:16
I recently tried to use backgroundworker instead of "classic" threads and I'm realizing that it's causing, at least for me, more problems than solutions. I have a backgroundworker running a synchronous read (in this case from serialPort) and getting blocked around 30 seconds in 1 code line, then cancellationpending isn't the solution. I'm seeing that if the application gets closed at this point (either with the cross button and Application.Exit()) the process keeps zombie forever. I need a way to force abort or to kill the backgroundworker thread. I'm not very sure on what you're trying to

How can I create WPF controls in a background thread?

心已入冬 提交于 2019-12-04 02:59:25
问题 I have method which create background thread to make some action. In this background thread I create object. But this object while creating in runtime give me an exception : The calling thread must be STA, because many UI components require this. I know that I must use Dispatcher to make reflect something to UI. But in this case I just create an object and dont iteract with UI. This is my code: public void SomeMethod() { BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += new

BackgroundWorker exception handling

无人久伴 提交于 2019-12-04 02:16:58
I'm working with the following components: a Library (which throws an exception) a test-console to test my logging the enterprise library exception handling application blocks the enterprise library logging application blocks I'm invoking the library method by using a backgroundworker. The library throws the exception but the RunWorkerCompleted handler is never called. The only way to catch the exception is to surround my DoWork handler code with a try/catch block. Did is misunderstand the RunWorkerCompletedEventArgs.Error Property? Isn't it for getting exceptions which got caught by the

How to yield return inside anonymous methods?

微笑、不失礼 提交于 2019-12-03 23:19:18
问题 Basically I have an anonymous method that I use for my BackgroundWorker : worker.DoWork += ( sender, e ) => { foreach ( var effect in GlobalGraph.Effects ) { // Returns EffectResult yield return image.Apply (effect); } }; When I do this the compiler tells me: "The yield statement cannot be used inside an anonymous method or lambda expression" So in this case, what's the most elegant way to do this? Btw this DoWork method is inside a static method, in case that matters for the solution. 回答1: