title: Iterating through an array and play notes
body: <p>I have an array which is populated by MusicNotes. Each MusicNote is an object with it's properties, e.g. pitch and duration. Duration is created using a timer in the MusicNote class.</p>
  
  <p>The problem is that when I iterate through the array and play all the sounds the duration of each MusicNote is lost and it will play the whole wav file (for each note).</p>
  
  <p>I know that the problem is related to the timer and I know that it maybe related to the Play() method in the MusicNote but I don't have any ideas on how to fix it. I have posted my the code related to this problem.</p>
  
  <pre><code>public class MusicNote : PictureBox
      {
          Timer tmr1 = new Timer();
          int tmr1duration;
          public SoundPlayer sp = new SoundPlayer();
          public Timer tmr = new Timer();
          public int pitch;        //The no. of the music key (e.g. the sound freuency).
          public int noteDuration; //Shape of note.
          public string noteShape;
          static int xLoc = 0;
          int yLoc = 100;
  
          public MusicNote(int iPitch, int iNoteDuration)
              : base()
          {
              pitch = iPitch;
              noteDuration = iNoteDuration;
              Size = new Size(40, 40);
              this.BackColor = Color.Transparent;
              this.MouseClick += new MouseEventHandler(MusicNote_MouseClick);
              this.MouseDown += new MouseEventHandler(MusicNote_MouseDown);
              this.MouseUp += new MouseEventHandler(MusicNote_MouseUp);
              tmr1.Tick += new EventHandler(tmr1_Tick);
              tmr.Tick += new EventHandler(ClockTick);
          }
  
          public void ShowNote()
          {
              if (this.noteDuration == 1) noteShape = "Quaver.png";
              if (this.noteDuration == 4) noteShape = "Crotchet.png";
              if (this.noteDuration == 7) noteShape = "minim.png";
              if (this.noteDuration == 10) noteShape = "DotMin.png";
              if (this.noteDuration == 12) noteShape = "SemiBreve.png";
              this.BackgroundImage = Image.FromFile(noteShape);
              this.BackColor = Color.Transparent;
              Location = new Point(xLoc, yLoc);
              xLoc = xLoc + 40;
          }
  
          protected override void OnPaint(PaintEventArgs pe)
          {
              base.OnPaint(pe);
          }
  
          public void Play()
          {
              sp.SoundLocation = this.pitch + ".wav";
              sp.Play();
              //Timer to play the duration
              this.tmr.Interval = 100 * this.noteDuration;
              this.tmr.Start();
          }
  
          void ClockTick(object sender, EventArgs e)
          {
              sp.Stop();
              tmr.Stop();
          }
  
          private void MusicNote_MouseClick(object sender, MouseEventArgs e)
          {
              if (e.Button == MouseButtons.Left)
              {
                  Play();
              }
          }
      }
  }
  </code></pre>
  
  <p>And this is the class were I have the array...</p>
  
  <pre><code>   public class MusicStaff: Panel
      {
          public ArrayList musicNotes = new ArrayList(); //Array to store the Music Notes.
          SoundPlayer sp = new SoundPlayer();
  
          public void AddNote(MusicNote newNote)         //Method to add the notes.
          {
              musicNotes.Add(newNote);
          }
  
          public int ListSize()
          {
              return musicNotes.Count;                   //Returns the size of the list.
          }
  
     public void PlayAll()
      {
          foreach (MusicNote m in musicNotes)
          {
              m.Play();
          }
  </code></pre>
  
  <p>I have removed some code from the classes which is not replated to the problem so that question is not too long. Any help how can I solve this would be greatly appreciated. Tks.</p>