//Thread Method private void ProcessFile2(object state) { ThreadInfo2 threadInfo = state as ThreadInfo2; LabelDelegate FuncName = threadInfo.FuncName; int index = threadInfo.SelectedIndex; //this.Invoke(new LabelDelegate(UpdateLabel)); //Invoke delegate function FuncName.Invoke("ProcessFile2 is invoked"); }
private void btnThreadPool2_Click(object sender, EventArgs e) { rtbResults.Text = string.Empty; ThreadInfo2 threadInfo = new ThreadInfo2(); threadInfo.FuncName = UpdateLabel; threadInfo.SelectedIndex = 3; //ThreadPool.QueueUserWorkItem(new WaitCallback(ProcessFile2), threadInfo); //1 thread & include Join() //var thread = new Thread(() => { ProcessFile2(threadInfo) }); //thread.Start(); //thread.Join(); //do no use if you want to label to be updated var task = Task.Factory.StartNew(() => { ProcessFile2(threadInfo); }); //task.Wait(); //do no use if you want to label to be updated label1.Text = "Done"; }