C# – SoundPlayer crash on Vista

audiocwindows-vistawinforms

The following code is causing an intermittent crash on a Vista machine.

using (SoundPlayer myPlayer = new SoundPlayer(Properties.Resources.BEEPPURE))
     myPlayer.Play();

I highly suspect it is this code because the program crashes mid-beep or just before the beep is played every time. I have top-level traps for all ThreadExceptions, UnhandledExceptions in my app domain, and a try-catch around Application.Run, none of which trap this crash.

Any ideas?


EDIT:

The Event Viewer has the following information:

Faulting application [xyz].exe, version 4.0.0.0, time stamp
0x48ce5a74, faulting module msvcrt.dll, version 7.0.6001.18000, time
stamp 0x4791a727, exception code 0xc0000005, fault offset 0x00009b30,
process id 0x%9, application start time 0x%10.

Interestingly, the HRESULT 0xc0000005 has the message:

"Reading or writing to an inaccessible memory location."
(STATUS_ACCESS_VIOLATION)

Best Answer

Actually, the above code (that is, new SoundPlayer(BEEPPURE)).Play(); was crashing for me.

This article explains why, and provides an alternative to SoundPlayer that works flawlessly:

http://www.codeproject.com/KB/audio-video/soundplayerbug.aspx?msg=2862832#xx2862832xx

Related Topic