private void btnTestProgress_Click(object sender, EventArgs e) { //reset the progress bars to prevent them causing out of bounds errors resetProgressIndicators(); //determine which button checked if (rdoSpinner.Checked) { dpt = new delegateProgressType(increaseSpinner); } else if (rdoProgressBar.Checked) { dpt = new delegateProgressType(increaseProgBar); } else if (rdoTrackbar.Checked) { dpt = new delegateProgressType(increaseTrackBar); } //pass slow method the delegate we just defined slowMethod(dpt); }
//Artificially slow down progress private void slowMethod(delegateProgressType delegateProgressType) { //Sleep 10 times to simulate progress for (int i = 0; i < 10; i++) { //Sleep 1s Thread.Sleep(1000); //Run the function bound to the passed in delegate instance delegateProgressType(); } }