Note that there are some explanatory texts on larger screens.

plurals
  1. POThread and Invoke, how to modify a label?
    primarykey
    data
    text
    <p>I work on an application in c# and I have a problem with my thread and my UI...</p> <p>I want to add +1 on my label when the thread is running. The problem is I don't know how I can fix that... I have read a lot of "how to" but the solutions donc work with my app..</p> <p>My thread class:</p> <pre><code> class clsWorker { //Thread myThread = new Thread(new ThreadStart(ThreadLoop)); public SerialPort port; public String url; Thread t; clsSMS clsobjSMS = new clsSMS(); SMSapplication clsobjAPP = new SMSapplication(); public clsWorker(SerialPort serialPort, String urlChamp) { this.port = serialPort; this.url = urlChamp; } public void StartThread() { t = new Thread(new ThreadStart(ThreadLoop)); t.Start(); } public void ThreadLoop() { // How I can add +1 on the countSMSok label ?? clsobjAPP.updateCountSMS("countSMSok"); } } </code></pre> <p>My application class :</p> <pre><code>public partial class SMSapplication : Form { public void updateCountSMS(String label) { int num; this.countSMSnok = new System.Windows.Forms.Label(); this.countSMSok = new System.Windows.Forms.Label(); this.Controls.Add(this.countSMSnok ); this.Controls.Add(this.countSMSok ); if (label == this.countSMSok.Name.ToString()) { if (int.TryParse(this.countSMSok.Text.ToString(), out num)) this.countSMSok.Invoke((MethodInvoker)(() =&gt; this.countSMSok.Text = num++.ToString())); } else if (label == this.countSMSnok.Name.ToString()) { if (int.TryParse(this.countSMSnok.Text.ToString(), out num)) this.countSMSnok.Invoke((MethodInvoker)(() =&gt; this.countSMSnok.Text = num++.ToString())); } } private void btnRequestStart_Click(object sender, EventArgs e) { this.btnRequestStart.Enabled = false; this.btnRequestStop.Enabled = true; objclsWorker = new clsWorker(this.port, this.urlChecker.Text); objclsWorker.StartThread(); } } </code></pre> <p>Thanks you very very much for your helping !</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload