I have a question about the meaning of progressbar show.
I have this main thread
private void button1_Click(object sender, EventArgs e) { progress prog = new progress(); progress.progressEvent += new progress.progressEventHandler(progressEvent); for(int i=0;i<100;i++) { Thread.Sleep(100); prog.incA(); } }
void progressEvent(object sender) { if (progressBar1.InvokeRequired) { //Tady mi to caka az kym nedobehne cyklus for a pak zacne tohleto fungovat progressBar1.Invoke(new ChangeProgressBarValue(ProgressStep)); } else { ProgressStep(); } }
public void ProgressStep() { progressBar1.PerformStep(); }
public class progress { private ThreadStart ts; private Thread th; private bool status = true; public delegate void progressEventHandler(object sender); public static event progressEventHandler progressEvent; private int b,a = 0;
public progress() { ts=new ThreadStart(go); th = new Thread(ts); th.IsBackground = true; th.Start(); }
public void incA() { a++; if(a==100) status = false; }
private void go() { while (status) { if (a != b) { b = a; if (progressEvent != null) progressEvent(this); } } th.Abort(); } }
and my problem is that IF starts the main thread and calls IncA this is a method call event, and in the case of invadbar invoke and this causes the main thread to wait FOR
why wait? THX
source share