I have an application that I'm trying to write in C#. This is my first application using C#, so please bear with me.
I tried to create a small app with a textbox and two buttons: start and stop. The start button calls a function that iterates from 1 to 1000, and the stop button doesn't do anything. I've googled "threads" which looks to be what I want, but I don't know where to create the thread. I'm in the situation that I don't know enough about it to know what I'd even search for. (Man, that's frustrating enough.) I've got a bigger use for this function in another application that I'm doing for work, but I have to figure this part out before I can move on with my other project.
So, I understand what threads are. I don't understand if I put them in the form load event or if I start the new thread when the start button is clicked. I tried to start 2 threads on form load, one for start and one for stop, but you can't assign a button_click event to a thread, so then I tried to assign the stop button click event to call another function which was assigned to another thread. I still couldn't click the stop button. Any help would be greatly appreciated!!
private void btnStart_Click(object sender, EventArgs e)
{
Thread myThread = new Thread(new ThreadStart(Stop));
myThread.Start();
Count();
}
private void Count()
{
for (int i = 0; i < 1000; i++)
{
this.textBox1.Text += i + "\r\n";
this.textBox1.Refresh();
}
}
private void btnStop_Click(object sender, EventArgs e)
{
Stop();
}
private void Stop()
{
Application.Exit();
}