Cross thread calls Windows Form Control

xiaoxiao2021-03-31  242

delegate void SetTextCallback (string text); private void SetText (string text) {// InvokeRequired required compares the thread ID of the // calling thread to the thread ID of the creating thread // If these threads are different, it returns true. ..Stbsuccess.invokerequired) {settextCallback D = new setxtCallback (setxt); this.invoke (d, new object [] {text});} else {this.stbsuccess.text = text;}}

Thread NewThread = New Thread (New ThreadStart (threadname)); // Create thread threadname.start ();

private BackgroundWorker backgroundWorker1; this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker (); this.backgroundWorker1.RunWorkerCompleted = new System.ComponentModel.RunWorkerCompletedEventHandler (this.backgroundWorker1_RunWorkerCompleted); private void setTextBackgroundWorkerBtn_Click (object sender, EventArgs e) {this.backgroundWorker1 . Runworkerasync ();

转载请注明原文地址:https://www.9cbs.com/read-131007.html

New Post(0)