I have little windows forms program that plays music using console.beep from strings. I have the string playing bit (which is basically a for loop that goes through the strings char by char and plays the appropriate note) set up in a new thread 't'. When you hit the "play" button the thread starts and the button changes to a "stop" button. If you hit this now "stop" button while the music is playing it will stop and the button changes back to play (by calling the "finished" method. My problem is that I want the loop running in the new thread to also call the "finished" method when the loop has run its course and the song is over. But if i put finished() after my loop i get the "object reference is required for the non static field" error. If I change the "finshed" method to static then the bit that changes the button text doesnt work...
Heres the code for when you press the button...
//This is the method for when the "start" button is clicked
public void button1_Click(object sender, EventArgs e)
{
if (music == null) { return; }
if (button1.Text == "Play")
{
// it makes a new thread which calls my "parse" method which
// interprets the music and then calls "playnote" to play it.
Thread t = new Thread(parse);
t.Start();
button1.Text = "Stop";
}
else
{
finished();
}
}
public void finished()
{
stop = true;
button1.Text = "Play";
}
Any suggestions?
Thanks a lot in advance!
Edit: Thanks all!! I dont really have time to figure out the background worker atm so I just have seperate start and stop buttons now! :p