2010-02-17 29 views
1

下面是從C#Windows窗體C#的WinForm不響應 - System.Speech - 幫助

SpeechSynthesizer audio = new SpeechSynthesizer(); 
audio.Speak(textBox1.Text); 
  • 這將讀什麼是在文本框中

問題在試圖代碼實現暫停和停止功能。當代碼讀取內容時,任何按鈕或菜單項都不會被點擊

public void button1_Click(object sender, EventArgs e) 
    { 
     //Nothing gets executed here when the code is reading 
    } 

我剛剛看了有SpeakProgressEventArgs http://msdn.microsoft.com/en-us/library/system.speech.synthesis.speakprogresseventargs%28VS.85%29.aspx

我試圖合成器... ... asyncancel但得到犯規執行

+0

SpeechSynthesizer是否在UI線程中運行?如果它與UI事件循環在同一線程中運行,您可能會遇到較差的UI響應。 –

回答

4

使用SpeakAsync()方法,而不是非常好解釋。這可以防止用戶界面在Speak()方法上被阻塞,它在阻止時不能響應按鈕點擊。你可以使用SpeakAsyncCancelAll()來阻止它在nattering上。

+0

問題解決。謝謝 – aBs0lut3z33r0

3

按鈕的點擊事件中,你需要管理使用Threads此塊audio.Speak(textBox1.Text);

 Thread t = new Thread(() => 
     { 
      SpeechSynthesizer audio = new SpeechSynthesizer(); 
      audio.Speak(textBox1.Text); 
     }); 
     t.Start(); 

現在如何停止正在運行的線程?在這張海報

+0

將嘗試使用解決方案建議實施多線程 – aBs0lut3z33r0