[英]How can I play a sound in a thread?
I want to play a beep for 1 second in thread. 我想在线程中发出哔哔声1秒钟。 I'm not familiar with threads and maybe there is another easy way without using threads. 我对线程不熟悉,也许还有另一种不使用线程的简单方法。 I used console.beep(), but unfortunately it freeze's the form for a second. 我使用了console.beep(),但是不幸的是它冻结了表格一秒钟。
while(true)
{
do some jobs;
console.beep();
}
The Winform app freeze on the console.beep(); Winform应用程序冻结在console.beep();上。 for one second. 一秒钟。 I need to pass the line and simultaneously beep for one second. 我需要通过线路并同时发出哔哔声一秒钟。
You can use 您可以使用
using System.Media;
SystemSounds.Beep.Play();
And Play() doesn't block so you don't need a Thread. 而且Play()不会阻塞,因此您不需要线程。 It plays whatever is configured in the User's sytem sound settings. 它会播放用户系统声音设置中配置的任何内容。
But if you need to know when the sound has finished this is not what you want. 但是,如果您需要知道声音何时结束,这不是您想要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.