dcsimg
Results 1 to 10 of 10

Thread: Is the command to check if the bell is running or stopped ?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Posts
    403

    Is the command to check if the bell is running or stopped ?

    I have the following C # statement:
    Code:
    ...
    using (SoundPlayer player = new SoundPlayer(Properties.Resources.ring))
    {
    player.Play();
    
      //What should I write here? 
      while (If the bell is running, wait here)
      {
          if (player.Stop()==true)
          {
              this.progressBarControl1.Visible = false; //false = không cho phép hiện
          }
      }
    }
    ...
    I want to check if the ringer is running or stopping, if it is running then wait until it stops before running this.progressBarControl1.Visible = false.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    103,319

    Re: Is the command to check if the bell is running or stopped ?

    You should be calling PlaySync rather than Play. You should already know that because you should have read the relevant documentation and seen it.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Posts
    403

    Re: Is the command to check if the bell is running or stopped ?

    method "PlaySync" does not check the status "ON / OFF" when the bell rings, you see my code.
    Code:
    public Form1()
            {
                InitializeComponent();
                lblStatusPlaySound.ForeColor = Color.Violet;
                lblStatusPlaySound.Text = "Status: OFF/ON";
            }
            private void btnPlaySound_Click(object sender, EventArgs e)
            {
                lblStatusPlaySound.ForeColor = Color.Green;
                lblStatusPlaySound.Text = "Status: ON";
    
                using (SoundPlayer player = new SoundPlayer(Properties.Resources.ring))
                {
                    player.PlaySync();
                }
    
                lblStatusPlaySound.ForeColor = Color.Red;
                lblStatusPlaySound.Text = "Status: OFF";
            }

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    103,319

    Re: Is the command to check if the bell is running or stopped ?

    Of course it doesn't check. It does what it says it does: plays a sound synchronously. The method doesn't return until the sound has finished playing so what could there be to check for?

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,239

    Re: Is the command to check if the bell is running or stopped ?

    If you mean the label doesn't display "on" (it only displays "off" when the sound stops), that is expected... controls don't redraw themselves while code is running.

    One way to deal with it is to make the label redraw immediately:
    Code:
                lblStatusPlaySound.Text = "Status: ON";
                lblStatusPlaySound.Refresh

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Posts
    403

    Re: Is the command to check if the bell is running or stopped ?

    Thank you very much

  7. #7
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    103,319

    Re: Is the command to check if the bell is running or stopped ?

    Quote Originally Posted by dong View Post
    method "PlaySync" does not check the status "ON / OFF" when the bell rings
    So, it appears that what you actually meant was that the Text of the Label doesn't appear to change while the sound is playing. Obviously language is an issue here but I would suggest trying to be a bit clearer in your posts. It seems to me that those with communication challenges seem to try to write fewer words when what they need to do is write more. For instance, if you had said something like:
    When I click the Button, I expect to see the Label display "Status: ON", then the sound will play and then the Label will display "Status: OFF" when it finishes. What I actually see is the Label not change at all until the sound finishes.
    then it would be clear what you actually mean. Even if the English wasn't perfect, the meaning would still come through more easily. The fewer words there are, the less context we have to be able to interpret the parts that are wrong.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Posts
    403

    Re: Is the command to check if the bell is running or stopped ?

    Now I understand, I think the friend when my readers will understand and at that time I did not understand because the status of the line when running it did not refresh while I assigned ON or OFF status for each statement to check display status, this makes you uncomfortable reading my article, I will learn from experience next time I will try to add more description in my understanding, thank you for reading my article .

  9. #9
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,535

    Re: Is the command to check if the bell is running or stopped ?

    Quote Originally Posted by dong View Post
    ... I will learn from experience next time I will try to add more description in my understanding, thank you for reading my article .
    I'm sure if I had to post in Vietnamese, the results would be much worse.
    As for learning from experience, if in the future you use the word "post" instead of "article", it will be one simple lesson completed.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Posts
    403

    Re: Is the command to check if the bell is running or stopped ?

    In Vietnam, the computer forum is less developed and vibrant as your forum. Thank you for your Feedback on fixes my spelling.
    Last edited by dong; Nov 12th, 2019 at 09:03 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width