button执行该语句Beep后程序会卡住,开启一个线程执行该语句也会如此,怎么解决呢
for(int i=0;i<50;i++)
{
Beep(600,6000)
Sleep(500);
}
笔记本 VS2010,求解!
------解决方案--------------------
BOOL WINAPI Beep(
__in DWORD dwFreq,
__in DWORD dwDuration
);
Parameters
dwFreq
The frequency of the sound, in hertz. This parameter must be in the range 37 through 32,767 (0x25 through 0x7FFF).
Windows Me/98/95: The Beep function ignores this parameter.
dwDuration
The duration of the sound, in milliseconds.
------解决方案--------------------
Generates simple tones on the speaker. The function is synchronous; it performs an alertable wait and does not return control to its caller until the sound finishes.
来自msdn:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms679277(v=vs.85).aspx
------解决方案--------------------
我用C#写的,没卡主啊。
private void button1_Click(object sender, EventArgs e)
{
ThreadStart starter = new ThreadStart(ThreadFunc);
Thread thread = new Thread(starter);
thread.Start();
}
private void ThreadFunc()
{
for (int i = 0; i < 3; i++)
{
Beep(600, 6000);
System.Threading.Thread.Sleep(500);
}
MessageBox.Show("thread finish");
}
[DllImport("kernel32.dll")]
public static extern bool Beep(int freq, int duration);
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("clicked");
}