stop button

closed account (4w7X92yv)
I got a form with a start and stop button, when i press starts it executes my code, but when i stop it doesnt stop it
What do i do wrong?


in form1.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
				 this->demoThread =
                gcnew Thread(gcnew ThreadStart(this,&Form1::doTheWork));

				this->demoThread->Start();
				 btnStart->Enabled = false;
				 btnstop->Enabled = true;

				 lblText->Text = "Program started";
				 lstStatus->Items->Clear();
				 lstStatus->Items->Insert(0,"Program started");
				bool terminate = false;
			 }

private: System::Void btnstop_Click(System::Object^  sender, System::EventArgs^  e) {

				lstStatus->Items->Clear();
				lstStatus->Items->Insert(0,"Program stopped");
				lblText->Text = "Program stopped";
				 btnstop->Enabled = false;
				 btnStart->Enabled = true;
				bool terminate = true;


in main

1
2
3
4
5
6
7
8
int myMain(System::Windows::Forms::ListBox^ lstStatus)
{  do
{

// the code that is executed

}while (terminate == false);
}


when i press the start it places terminate on false and executes my code.
when i press stop it places terminate on true but still executes my code,
how do i get out of the thread by using the stop button
For .net questions it is best if you post @ the MSDN forums. Almost nobody here does C++/CLI.
closed account (4w7X92yv)
but im on the c++ general programming
joriek wrote:
but im on the c++ general programming


Yes, and? It doesn't change the fact that your code is C++/CLI and that almost nobody here knows or does C++/CLI. And actually your question is not about general C++ programming, it is about specific Windows programming and therefore should have been better to post in the Windows forum.

But all aside, if you really want an answer, post your question at the Microsoft MSDN Forums.
closed account (4w7X92yv)
ok sry, thanks
Yes, but that's C++/CLI, not C++. This belongs in the Windows forum. Not sure what exactly you're trying to stop, but wouldn't the thread you start in button1_Click be one of the things you'd need to stop?
closed account (4w7X92yv)
yes thats what i want, do you know how to do that?

thanks
Save the reference to the thread. It probably has a kill() or terminate() method or something the like, look up the documentation of Thread (at msdn).
Your problem is that you declare local variables in lines 12 and 22 and set them to a value. They don't affect the value of the variable checked in line 7 of myMain().
Topic archived. No new replies allowed.