private static void FreeHandle() { if (gcHandle != null) { Win32.PlaySound((byte[])null, UIntPtr.Zero, 0); gcHandle.Value.Free(); gcHandle = null; } }
public static void PlaySound(System.IO.Stream stream, SoundFlags flags) { LoadStream(stream); flags |= (SoundFlags.SND_MEMORY | SoundFlags.SND_ASYNC); if (BytesToPlay != null) { // The byte array is pinned so that garbage collector cannot move it. gcHandle = System.Runtime.InteropServices.GCHandle.Alloc(BytesToPlay, System.Runtime.InteropServices.GCHandleType.Pinned); Win32.PlaySound(gcHandle.Value.AddrOfPinnedObject(), UIntPtr.Zero, (uint)flags); } else { Win32.PlaySound((byte[])null, UIntPtr.Zero, (uint)flags); } }