Note that there are some explanatory texts on larger screens.

plurals
  1. POMaking Events using Threads
    text
    copied!<p>I have created a "Windows Form" and a second "Thread" .</p> <ul> <li><p>My form has a button that changes the value of a variable .</p></li> <li><p>My second thread uses an unstoppable loop to analyze that variable .</p></li> </ul> <p>So this is an event that Changes the text of the form when the value of a that variable changes , but I cannot have my form or any of controls in the blocks of that "ThreadProcess" function because it is declared after that .</p> <p>I also cannot declare my form before it because I need to use "ThreadClass" in form constructor . What should I do then ?</p> <pre><code>using namespace System; using namespace System :: Threading; using namespace System :: Windows :: Forms; namespace Program { static int Number = 0; ref class ThreadClass { public : void ThreadProcess () { int SavedNumber = Number; while (1) { if(Number != SavedNumber) { this -&gt; Text = "Changed"; SavedNumber = Number; } else this -&gt; Text = "Nothing Yet"; } } } ; ref class MainForm : Form { Button ^ ChangeButton; Thread ^ EventThread; ThreadClass ^ EventThreadClass; public : MainForm () { EventThreadClass = gcnew ThreadClass ; EventThread = gcnew Thread ( gcnew ThreadStart ( EventThreadClass, &amp; ThreadClass :: ThreadProcess ) ) ; EventThread -&gt; IsBackground = true; ChangeButton = gcnew Button (); ChangeButton -&gt; Click += gcnew EventHandler (this, &amp; MainForm :: CloseButtonEventProcess); Controls -&gt; Add (ChangeButton); EventThread -&gt; Start (); } void CloseButtonEventProcess (Object ^ Sender , EventArgs ^ EA) { Number ++; } } ; } </code></pre>
 

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