Jump to content

Recommended Posts

Posted

A mate of mine is having the following issue with his coursework, it has me stumped, so I was wondering if anybody had any suggestions!

 

Seemingly simple command, trying to show the text "Making noise" whenever an animal in my Zoo program makes a noise. It doesn't seem to use that text though, instead it will run whatever method is selected, but will seemingly stay as "Nothing" in my label. If I get rid of the "Nothing" at the end of the if/elses, it will change to "Making noise" after my methods have run.

 

        private void btnNoise_Click(object sender, EventArgs e)
       {
           labState.Text = "Making noise";
           //System.Threading.Thread.Sleep(500);

           if ((radCats.Checked) && (radOne.Checked))
           {            
               Zoo[0].MakeNoise();
           }
           else
           if ((radCats.Checked) && (radTwo.Checked))
           {
               Zoo[1].MakeNoise();
           }
           else
           if ((radDogs.Checked) && (radOne.Checked))
           {
               Zoo[2].MakeNoise();
           }
           else
           if ((radDogs.Checked) && (radTwo.Checked))
           {
               Zoo[3].MakeNoise();
           }
           else
           if ((radTigers.Checked) && (radOne.Checked))
           {
               Zoo[4].MakeNoise();
           }
           else
           {
           }
           //System.Threading.Thread.Sleep(500);
           labState.Text = "Nothing";
       }

 

 

Also, the MakeNoise() method isn't instantly over, there are System.Threading.Thread.Sleeps in those too.

Posted
If makeNoise runs in the same thread then the interface might only update after the sound has played. Ideally you'll need to have a new thread for the sound and launch that.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...