1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
private: void ThrFunc()
{
while(1)
{
Random ^rnd = gcnew Random();
int mesure = rnd->Next(100);
this->textBoxMesure->Text=mesure.ToString();
}
}
private: System::Void buttonMesurer_Click(System::Object^ sender, System::EventArgs^ e) {
// ThrFunc est la fonction exécutée par le thread.
_Thread = gcnew Thread(gcnew ThreadStart(this, &Form1::ThrFunc));
// Il est parfois pratique de nommer les threads surtout si on en créé plusieurs.
_Thread->Name = "Thread1";
// Démarrage du thread.
_Thread->Start();
} |