日期:2014-05-18  浏览次数:20814 次

单击按钮,启动线程,主线(界面)无响应,子线程结束后才会恢复,如何解决??
C# code

private void playButton_Click(object sender, EventArgs e)
        {
            Button playBtn = sender as Button;
            string text=testBox.Text;
            if(null == text || text.Length <1) {
                MessageBox.Show("输入文本");
                return;
            }
            speek.Text=text;
            speek.Name = voiceCombo.SelectedItem as string;
            speek.Rate = (int)rateUpDown.Value;
            speek.Volume = (int)volumeUpDown.Value;
            speek.Index = 0;

            Thread th   =   new   Thread(new   ThreadStart(PlayText));
            th.IsBackground = true;
            th.Start();
        }
        
        
private void PlayText() 
{
            speek.Say();
        }




//Speek类封装TTS的操作。启动线程后,主界面不能响应,只有子线程返回后
才能继续响应子线程,怎么解决啊???

------解决方案--------------------
ParameterizedThreadStart threadstart = new ParameterizedThreadStart(PlayText);
Thread exeThread = new Thread(threadstart);
exeThread.Start();

随手翻个项目 是这么写的
------解决方案--------------------
C# code


        private void btnStartThread_Click(object sender, EventArgs e)
        {
            Thread th = new Thread(new ThreadStart(Start));
            th.IsBackground = true;
            th.Start();
        }
        void Start()
        {
            while (true)
            {
                Thread.Sleep(5000);
            }
        }

------解决方案--------------------
没找到问题
Speek类的代码贴出来看看
是不是这里卡主线程了
------解决方案--------------------
这个类也没卡
建议主线程看看有没有卡得
或者Voice类
------解决方案--------------------
我估计和微软的TTS控件有关,和多线程无关。是不是TTS就不许多线程
------解决方案--------------------
http://blog.csdn.net/hukeda0509/article/details/5586437
th.IsBackground = true; 会不会是错误根源??


另外,TTS 发声引擎,这种操作声卡的操作,子线程 到底有没有权利?
子线程冒似连界面UI都没有权限操作的?

http://topic.csdn.net/u/20110321/10/20e23804-4868-4ea2-95b0-0324619bf03f.html
遇到了和你一样的错误....