
// e.Cancel = true Cannot read e.Result if e.Cancle is true.bw.ReportProgress(50, "User Canceled" ).BackgroundWorker bw = (BackgroundWorker) sender.void bw_DoWork( object sender, DoWorkEventArgs e).// Have to display the form so that you can see what is going on.fpv.START_WORK() // best to set dialog options before you start the working thread.fpv.SET_WORKER_METHOD = new DoWorkEventHandler(bw_DoWork).fpv.CONTINOUS_PROGRESS = true // Progress reporting does not update the progressbar. The internal timer does so that the bar just cycles.fpv.RUN_ONLY_ONCE = false // lets the user cancel and click start over and over.fpv.Text = "SOME TEXT" // Sets the dialog Caption.FormProgressViewer fpv = new FormProgressViewer().private void butTestBW_Click( object sender, EventArgs e).The nuts and bolts of the the form are as suchįirst you need to assign a method that will do the work. The trick is that this method can be created out side of the form as long has it matches the signature of the DoWorkEventHandler. Here is the property for the FormProgressViewer. Here is the FormProgessViewer when task complete or cancled I added some basic elements. A lable so that the messages passed to the backgroundworker could be displayed. A richtextbox (default not visible but infront of the lable) to hold all of the messages. A toggle button to determine what you want to display (current message or all messages). A start button (not visible during task running) A cancel button (disabled during non running tasks) and an OK button to close form when task is complete. So I created a simple form that you pass the dowork method to. Then just display the form viola you have a nice progress bar running over and over. But I do want to do "stuff" from time to time and I don't want to have to rethink the whole threading process over and over. I don't necessarily want to fill a data grid or make a SQL call or calculate Fibonacci numbers. That is to get the form to show the actual progress.īut this is all very complicated. Every article I have seen written goes on and on about how to implement the background worker but never discusses how to put the whole meal deal together. Have you ever tried to get a background worker to display a progressbar.
