• 0

[C#]Label not immediately updating..


Question

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, so it's not like it should be too fast for a user to see.

Edited by GC_Trojan
Link to comment
Share on other sites

8 answers to this question

Recommended Posts

  • 0
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, so it's not like it should be too fast for a user to see.

can you show the makenoise method?

Link to comment
Share on other sites

  • 0
can you show the makenoise method?

Ok, in my parent class, Animal.cs it is:

		public virtual void MakeNoise()
		{  
			player.Play();  
		}

And in for the child class, i.e. Cat.cs it is:

		public override void MakeNoise()
		{
			for (int i = 0; i < 2; i++)
			{ 
				player.Stream = Properties.Resources.catmeow;
				base.MakeNoise();
				System.Threading.Thread.Sleep(1500);
			}
		}

Link to comment
Share on other sites

  • 0

What are you using to play the audio stream? What could be happening is that the player plays the audio using its own thread, which means the UI thread isnt being used to play it. If that is the case, it will start the thread using the player, and complete the click event at which it sets the text to "Nothing". This would happen very quickly, so it will appear not to be setting the value.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.