两个按钮不能同时工作. [英] two button is not working in same time.
本文介绍了两个按钮不能同时工作.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好:
我有2个按钮和1个文本框,当我单击按钮1时,它会从文本框"TTS"中读取我的文本.但是我想通过单击第二个按钮停止阅读,第二个按钮或其他控件在reading时不起作用.线程进入计时器,但我找不到可接受的解决方案.
请帮我
hi to all gentleman:
i have 2 button and 1 textbox,when i click button 1 it read my text from textbox"TTS".But i want to stop reading by clicking second button,second button or other contrlos are not working in the time of reading.i try thread in timer but i did not find acceptable solution .
pleas help me
sorry for long question.
推荐答案
也许,读取文本功能太短,并且此过程将过快传递,导致您无法停止阅读.
想法:
Maybe, the read text function is too short, and the process of this will be passed too fast, cause to you cannot stop reading.
Idea about this:
private System.Threading.Thread thread;
public void ReadText()
{
string tmp = "";
//for (int i = 0; i < 100000; i++)
//{
//tmp += "Text" + i.ToString();
//}
System.Threading.Thread.Sleep(3000);//Pause 3 seconds before read text in textbox
tmp = textBox1.Text;
}
private void button1_Click(object sender, EventArgs e)
{
thread = new System.Threading.Thread(ReadText);
thread.Start();//Begin execute function ReadText
}
private void button2_Click(object sender, EventArgs e)
{
if (thread != null && thread.ThreadState == System.Threading.ThreadState.Running)
{
thread.Suspend();//Pause thread of function ReadText
//If you want to stop, use:
//thread.Abort();
}
}
更新:
请尝试:
Updates:
Please Try:
public void readText()
{
if (textBox1.Text != "")
{
System.Threading.Thread.Sleep(2000);//Pause 2 secs to do Speak function to exec
spvoice.Speak(textBox1.Text, SpeechVoiceSpeakFlags.SVSFlagsAsync);
System.Threading.Thread.Sleep(2000);//Pause 2 secs to do WaitUntilDone function to exec
spvoice.WaitUntilDone(Timeout.Infinite);
}
else
MessageBox.Show("please insert your text to richtextbox");
}
安迪.
Andy.
这篇关于两个按钮不能同时工作.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文