c# - "Managed Debugging Assistant ' RaceOnRCWCleanup ' has detected a p‌r‌o‌b‌l‌e‌m in "贾维斯

标签 c# visual-studio-2013 artificial-intelligence

我在一些互联网资源的帮助下创建了以下程序来创建 Jarvis:

namespace JarvisFile1
{
    public partial class Form1 : Form
    {
        private void Form1_Load(object sender, EventArgs e)
        {
            _recognizer.SetInputToDefaultAudioDevice();
            _recognizer.LoadGrammar(new Grammar(new GrammarBuilder(new Choices(File.ReadAllLines(@"C:\Users\Nelson\Documents\JarvisCommands\greetings.txt")))));
            _recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(_recognizer_SpeechRecognized);
            _recognizer.RecognizeAsync(RecognizeMode.Multiple);
        }

        SpeechRecognitionEngine _recognizer = new SpeechRecognitionEngine();
        SpeechSynthesizer JARVIS = new SpeechSynthesizer();
        string QEvent;
        string ProcWindow;
        double timer = 10;
        int count = 1;
        Random rnd = new Random();

        public Form1()
        {
            InitializeComponent();
        }


        void _recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            int ranNum = rnd.Next(1, 10);
            string speech = e.Result.Text;
            switch (speech)
            {
                //GREETINGS
                case "hello":
                case "hello jarvis":
                    if (ranNum < 6) { JARVIS.Speak("Hello sir"); }
                    else if (ranNum > 5) { JARVIS.Speak("Hi"); }
                    break;
                case "goodbye":
                case "goodbye jarvis":
                case "close":
                case "close jarvis":
                    JARVIS.Speak("Until next time");
                    Close();
                    break;
                case "jarvis":
                    if (ranNum < 5) { QEvent = ""; JARVIS.Speak("Yes sir"); }
                    else if (ranNum > 4) { QEvent = ""; JARVIS.Speak("Yes?"); }
                    break;
            }
        }
    }
}

编译器首先完美地编译它,然后给出以下错误消息:

"Managed Debugging Assistant 'RaceOnRCWCleanup' has detected a problem in 'C:\Users\Nelson\Documents\Visual Studio 2013\Projects\JarvisFile1\JarvisFile1\bin\Debug\JarvisFile1.vshost.exe'.

Additional information: An attempt has been made to free an RCW that is in use. The RCW is in use on the active thread or another thread. Attempting to free an in-use RCW can cause corruption or data loss."

我不太确定这意味着什么,因为我是编码初学者。 任何解决此问题的帮助将不胜感激。如果需要,我可以提供进一步的调试日志。我使用的是 Windows 8 和 Visual Studio 2013。

日志如下:

'JarvisFile1.vshost.exe' (CLR v4.0.30319: JarvisFile1.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Cannot find or open the PDB file. 'JarvisFile1.vshost.exe' (CLR v4.0.30319: JarvisFile1.vshost.exe): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\12.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll'. Cannot find or open the PDB file. 'JarvisFile1.vshost.exe' (CLR v4.0.30319: JarvisFile1.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll'. Cannot find or open the PDB file. 'JarvisFile1.vshost.exe' (CLR v4.0.30319: JarvisFile1.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'. Cannot find or open the PDB file. 'JarvisFile1.vshost.exe' (CLR v4.0.30319: JarvisFile1.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'. Cannot find or open the PDB file. 'JarvisFile1.vshost.exe' (CLR v4.0.30319: JarvisFile1.vshost.exe): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\12.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll'. Cannot find or open the PDB file. 'JarvisFile1.vshost.exe' (CLR v4.0.30319: JarvisFile1.vshost.exe): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\12.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'. 'JarvisFile1.vshost.exe' (CLR v4.0.30319: JarvisFile1.vshost.exe): Loaded 'c:\users\nelson\documents\visual studio 2013\Projects\JarvisFile1\JarvisFile1\bin\Debug\JarvisFile1.vshost.exe'. Cannot find or open the PDB file. 'JarvisFile1.vshost.exe' (CLR v4.0.30319: JarvisFile1.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'. Cannot find or open the PDB file. 'JarvisFile1.vshost.exe' (CLR v4.0.30319: JarvisFile1.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll'. Cannot find or open the PDB file. 'JarvisFile1.vshost.exe' (CLR v4.0.30319: JarvisFile1.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll'. Cannot find or open the PDB file. 'JarvisFile1.vshost.exe' (CLR v4.0.30319: JarvisFile1.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll'. Cannot find or open the PDB file. 'JarvisFile1.vshost.exe' (CLR v4.0.30319: JarvisFile1.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll'. Cannot find or open the PDB file. 'JarvisFile1.vshost.exe' (CLR v4.0.30319: JarvisFile1.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Deployment\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Deployment.dll'. Cannot find or open the PDB file. 'JarvisFile1.vshost.exe' (CLR v4.0.30319: JarvisFile1.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll'. Cannot find or open the PDB file. 'JarvisFile1.vshost.exe' (CLR v4.0.30319: JarvisFile1.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Speech\v4.0_4.0.0.0__31bf3856ad364e35\System.Speech.dll'. Cannot find or open the PDB file. The thread 0x1cf4 has exited with code 259 (0x103). The thread 0x11f8 has exited with code 259 (0x103). The thread 0xd6c has exited with code 0 (0x0). The thread 0x23c has exited with code 0 (0x0). The thread 0x610 has exited with code 259 (0x103). 'JarvisFile1.vshost.exe' (CLR v4.0.30319: JarvisFile1.vshost.exe): Loaded 'c:\users\nelson\documents\visual studio 2013\Projects\JarvisFile1\JarvisFile1\bin\Debug\JarvisFile1.exe'. Symbols loaded. 'JarvisFile1.vshost.exe' (CLR v4.0.30319: JarvisFile1.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'. Cannot find or open the PDB file. JarvisFile1.vshost.exe Information: 0 : SAPI does not implement phonetic alphabet selection. The thread 0x2270 has exited with code 259 (0x103). The thread 0x1b8 has exited with code 259 (0x103). The thread 0x1c2c has exited with code 259 (0x103). The thread 0x1650 has exited with code 259 (0x103). The program '[9444] JarvisFile1.vshost.exe: Program Trace' has exited with code 0 (0x0). The program '[9444] JarvisFile1.vshost.exe' has exited with code 0 (0x0).

最佳答案

看起来您需要释放或等待语音引擎资源被释放,直到关闭表单。该语音引擎可能有一个明确的调用来释放资源。只是猜测,但值得研究。

编辑:

取自MSDN网站

Always call Dispose before you release your last reference to the speech recognizer. Otherwise, the resources it is using will not be freed until the garbage collector calls the recognizer object's Finalize method.

您可以 Hook 事件 RecognizeCompleted,当您完成“停止”时,在引擎上调用release,然后调用 Close()

所以你会有代码:

        .
        .
        case "close jarvis":
        _recognizer.RecognizeCompleted += new EventHandler<RecognizeCompletedEventArgs>(_recognizer_RecognizeCompleted);
            JARVIS.Speak("Until next time");
            break;
        .
        .

    void _recognizer_RecognizeCompleted(RecognizeCompletedEventArgs e)
    {
      _recognizer.Release();
      Close();
    ]

由于您是编码新手,我想首先展示这种方式,因为您熟悉语法。但适合您的情况的更好方法是:

        case "close jarvis":
        _recognizer.RecognizeCompleted += (e) => { Close(); }
            JARVIS.Speak("Until next time");
            break;

这是内联事件处理程序而不是使用委托(delegate)。

关于c# - "Managed Debugging Assistant ' RaceOnRCWCleanup ' has detected a p‌r‌o‌b‌l‌e‌m in "贾维斯,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27995697/

相关文章:

c# - 在 asp.net 控件中访问全局资源

mysql - 如何从另一台PC在线连接到MySQL数据库?网络

visual-studio-2013 - Visual Studio 2013 Typescript 编译器不支持 '_references.ts' 文件

machine-learning - 偏差在神经网络中的作用是什么?

c# - 如何导出 C# 函数以便可以从非托管环境中调用它?

c# - 我应该将 LINQ DataContext 保留多长时间? ASP.Net页面

python - 为什么我的 connect4 minimax 不能正常工作?

algorithm - 如何并行化negamax算法?

c# - 如何在 C# 中设置 PropertyGrid 项的长度?

c++ - 使用 Visual Studio 2013 和 Intel Fortran 使用 Fortran 编译混合 C++/C 代码