How To Start And Stop A Continuously Running Background Worker Using A Button

Maybe you can use a manualresetevent like this, I didn’t debug this but worth a shot. If it works you won’t be having the thread spin its wheels while it’s waiting ManualResetEvent run = new ManualResetEvent(true); private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { while(run.WaitOne()) { //Kill zombies } } private void War() { run.Set(); } … Read more

Backgroundworker won’t report progress

You need to break your DoWork method down into reportable progress and then call ReportProgress. Take for example the following: private void Something_DoWork(object sender, DoWorkEventArgs e) { // If possible, establish how much there is to do int totalSteps = EstablishWorkload(); for ( int i=0; i<totalSteps; i++) { // Do something… // Report progress, hint: … Read more

WPF BackgroundWorker vs. Dispatcher

The main difference between the Dispatcher and other threading methods is that the Dispatcher is not actually multi-threaded. The Dispatcher governs the controls, which need a single thread to function properly; the BeginInvoke method of the Dispatcher queues events for later execution (depending on priority etc.), but still on the same thread. BackgroundWorker on the … Read more

File Copy with Progress Bar

You need something like this: public delegate void ProgressChangeDelegate(double Percentage, ref bool Cancel); public delegate void Completedelegate(); class CustomFileCopier { public CustomFileCopier(string Source, string Dest) { this.SourceFilePath = Source; this.DestFilePath = Dest; OnProgressChanged += delegate { }; OnComplete += delegate { }; } public void Copy() { byte[] buffer = new byte[1024 * 1024]; // … Read more

Can you link to a good example of using BackgroundWorker without placing it on a form as a component?

This article explains everything you need clearly. Here are the minimum steps in using BackgroundWorker: Instantiate BackgroundWorker and handle the DoWork event. Call RunWorkerAsync, optionally with an object argument. This then sets it in motion. Any argument passed to RunWorkerAsync will be forwarded to DoWork’s event handler, via the event argument’s Argument property. Here’s an … Read more