private void btnStart_Click(object sender, EventArgs e) { bool Checked = false; FeedBackDelegate feedBack = null; if (rdobtnSpinBox.Checked) { feedBack = new FeedBackDelegate(updateSpainBox); Checked = true; } if (rdobtnProgressBar.Checked) { feedBack = new FeedBackDelegate(updateProgressBar); Checked = true; } if (rdobtnTrackBar.Checked) { feedBack = new FeedBackDelegate(updateTrackBar); Checked = true; } if (Checked) { doingHeavyWork(feedBack); Checked = false; } }
private void doingHeavyWork(FeedBackDelegate feedBack) { for (int i = 0; i < 10; i++) { Thread.Sleep(200); feedBack(); } }
private void slowMethod(FeedBackDelegate feedback) { for (int i = 0; i < 10; i++) { Thread.Sleep(200); feedback(); } }
private void button1_Click(object sender, EventArgs e) { FeedBackDelegate feedBackDelegate = null; resetControls(); if (rdo_PBar.Checked) { feedBackDelegate = new FeedBackDelegate(updateProgressBar); } if (rdo_TrackBar.Checked) { feedBackDelegate = new FeedBackDelegate(updateTrack); } if (rdo_spin.Checked) { feedBackDelegate = new FeedBackDelegate(updateSpin); } if (feedBackDelegate != null) { slowMethod(feedBackDelegate); } }
private void btStart_Click(object sender, EventArgs e) { if(rbProgressBar.Checked) { progresDelegate = new FeedBackDelegate(updateProgressBar); }else if(rbSpinBox.Checked) { progresDelegate = new FeedBackDelegate(updateSpinBox); }else { progresDelegate = new FeedBackDelegate(updatetrackbar); } setProgressToZero(); for( int i =0 ; i < 10; i ++) { progresDelegate(); Thread.Sleep(500); Application.DoEvents(); } }