播放声音,等待它完成,然后做一些事情? [英] Play a sound, wait for it to finish and then do something?
问题描述
我正在写一个 Windows窗体这应该是打三的声音文件,并在应用每个声音文件的结尾,这是改变的图像的源。
I'm writing a Windows Forms application which is supposed to play three sound files and at the end of each sound file, it's to change the source of an image.
我可以得到它使用 System.Media.SoundPlayer
来播放声音。然而,似乎在不同的线程来播放声音,在继续。
I can get it to play the sounds using System.Media.SoundPlayer
. However, it seems to play the sound in a different thread, continuing on.
此的净效果是,只有最后一个播放声音和所有的图像被改变。
The net effect of this is that only the last sound is played and all the images are changed.
我试过 Thread.sleep代码
,但它睡觉了整个GUI和睡眠期发生的一切在一次后,最后的声音发挥它。
I've tried Thread.Sleep
, but it sleeps the whole GUI and after the sleep period everything happens at once and the last sound it played.
更新
我想PlaySynch在工作,但似乎冻结我的GUI这是不太理想。我还能怎么办?
I thought PlaySynch was working, but it seems to freeze my GUI which is less than ideal. What else can I do?
推荐答案
您是否尝试<一个href=\"http://msdn.microsoft.com/en-us/library/system.media.soundplayer.playsync.aspx\">SoundPlayer.PlaySync方法?从帮助:
的PlaySync方法使用当前
螺纹播放.wav文件,preventing
从处理其他线程
消息,直到加载完成。
The PlaySync method uses the current thread to play a .wav file, preventing the thread from handling other messages until the load is complete.
这篇关于播放声音,等待它完成,然后做一些事情?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!