C# 中 webControl 和 SAPI 的挂起问题

发布于 2024-10-29 02:34:44 字数 747 浏览 1 评论 0原文

可能的重复:
SAPI 或(文本到语音)… C# 的同步问题

我用WebControl制作了一个浏览器。现在我想阅读并突出显示文本。所以我分割了 then 句子并开始循环。现在的问题是,通过同步调用 SAPI 来说出句子,浏览器的所有其他按钮都会停止工作。我无法暂停、恢复甚至退出该软件。每个按钮都被挂起。

如果我使用SAPI的异步调用,则不会出现此问题,但文本的突出显示将不起作用。因此,我需要坚持这个同步调用,并解决这个挂起问题。有谁有解决办法吗!!!!!!!

for (int i = 0; i < splitSentences.Length; i++)
{
    highlight(splitSentences[i]);

    sound_object.Speak(splitSentences[i]);
}

请紧急需要帮助。我怎样才能在说出句子时找出浏览器的暂停、退出按钮......

Possible Duplicate:
Synchronization Problem for SAPI or (text to speech ) … C#

I've made a browser with WebControl. Now I want to read and highlight the text. So I split then sentences and start a loop.now the problem is, with a Synchronous call of SAPI to speak the sentences, every other button of the browser stops working. I can't pause, resume or even exit the software. Every button get hanged.

If I use a asynchronous call of SAPI, this problem doesn't occur, but then the highlighting of text will not work. So, I need to stick with this Synchronous call and also get over with this hang problem. Does anyone have any solution!!!!!!!

for (int i = 0; i < splitSentences.Length; i++)
{
    highlight(splitSentences[i]);

    sound_object.Speak(splitSentences[i]);
}

Please urgent help needed. How can I work out those pause, exit buttons of browser while speaking the sentece....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如何视而不见 2024-11-05 02:34:45

我认为你应该在 HighLight 函数中使用 Invoke。

例如,

void Do() //Must be start in another thread, not in main
{
    string [] splitSentences = new [] {"bye", "hello"};

    for (int i = 0; i < splitSentences.Length; i++)
    {
        HighLight(splitSentences[i], this);
        sound_object.Speak(splitSentences[i]);
    }
}

void HighLight(string str, Control webBrowser)
{
    if (this.InvokeRequired)
    {
        this.Invoke(new Action<string>(s, c => HighLight(s, c)));
    }

    // Highlight code here
}

I think you should use Invoke in HighLight function.

For example,

void Do() //Must be start in another thread, not in main
{
    string [] splitSentences = new [] {"bye", "hello"};

    for (int i = 0; i < splitSentences.Length; i++)
    {
        HighLight(splitSentences[i], this);
        sound_object.Speak(splitSentences[i]);
    }
}

void HighLight(string str, Control webBrowser)
{
    if (this.InvokeRequired)
    {
        this.Invoke(new Action<string>(s, c => HighLight(s, c)));
    }

    // Highlight code here
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文