Note that there are some explanatory texts on larger screens.

plurals
  1. POwhy value variable is not changed?
    primarykey
    data
    text
    <p>I have a <code>Timer</code> in my winForms and when the <code>TimeSpan</code> is <code>0</code> I set <code>done</code> as <code>true</code> and try check the value a thread. </p> <p>My code: </p> <p>Initial variables:</p> <pre><code>private DateTime endTime = DateTime.UtcNow.AddMinutes(1); private bool done; private bool running = true; private int count = 0; private delegate void setLabelMethod(string msg); private void setLabelValue(string msg) { label2.Text = msg; } </code></pre> <p>Timer handling:</p> <pre><code>private void timer1_Tick_1(object sender, EventArgs e) { TimeSpan remainingTime = endTime - DateTime.UtcNow; if (remainingTime &lt;= TimeSpan.Zero) { label1.Text = "Done!"; timer1.Enabled = false; done = true; running = false; } else { //... } } </code></pre> <p>Thread callback function: </p> <pre><code>private void test() { do { if (done) { Invoke(new setLabelMethod(setLabelValue), "yeah"); done = false; } Thread.Sleep(500); } while (running); } </code></pre> <p>Start <code>timer1_Tick</code> and <code>Thread</code> executions.</p> <pre><code> private void button2_Click(object sender, EventArgs e) { Thread th = new Thread(new ThreadStart(test)); th.Start(); timer1.Enabled = true; } </code></pre> <p>the problem is that the following statement in <code>.test()</code> method not ever is <code>true</code>,why?</p> <p><strong>statement</strong></p> <pre><code> if (done) { Invoke(new setLabelMethod(setLabelValue), "yeah"); done = false; } </code></pre> <p>Someone can point my mistake? Thanks in advance. </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