-8
private void button3_Click(object sender, EventArgs e)
    {
        OpenFileDialog ofd = new OpenFileDialog();
        ofd.Filter = "Music|*.mp3";
        if(ofd.ShowDialog()==DialogResult.OK)
        {
            SoundPlayer sp = new SoundPlayer(ofd.FileName);
            sp.Play();
        }
    }

I tried the given code but its not showing up.Instead of that program freezes. And off course there is already [STATHREAD] in main method.Please help!

DrKoch
  • 9,556
  • 2
  • 34
  • 43
Saurab
  • 1
  • 9
    PLeaser use the debugger, set breakpoints. Where exactly _freezes_ your program? What are the variables values (expected vs. actual)? What goes wrong? – DrKoch Mar 05 '15 at 07:16

1 Answers1

1

I'm guessing that the SoundPlayer's Play() method is a blocking call and so as you're running this on your UI thread it's preventing the UI from doing anything until it has finished playing.

Try launching the player as a separate thread and see if that causes your program not to freeze.

Ceisc
  • 1,278
  • 12
  • 18
  • 1
    `SoundPlayer.Play()` is the asynchronous call. The class has a `PlaySync()` method that is synchronous. So your theory is incorrect. The real problem here is that the OP didn't bother to provide a useful question that could be answered. Best to not try to answer such questions. – Peter Duniho May 27 '17 at 19:48