2
votes

I have created the following program with the help of some internet resources to create 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;
            }
        }
    }
}

The compiler compiles it perfectly at first and then gives the following error message:

"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."

I am not quite sure what this means as i am a beginner to coding. Any help to resolve this problem would be much appreciated. I can provide further debugging logs if required. I am using windows 8 and visual studio 2013.

The logs are given below:

'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).

1
When does this happen? When you try to shut down your program or when you first run it?Icemanind
The program does not respond as per expected. and then when i shut down the program it gives me this error. I can also provide you the logs if you need it..Nelson Menezes
I am running your same code on my machine and it seems to be working fine. Logs would probably help.Icemanind
Is this your entire program?Icemanind
Yes it is. BEsides this there is another text file that I have state here:Nelson Menezes

1 Answers

2
votes

It looks like you need to free or wait until your speech engine resources are free'd until you close the form. That speech engine probably has an explicit call to release the resources. Just a guess, but worth looking into.

edit:

Taken from the MSDN website

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.

You can hook into the event RecognizeCompleted and when you get a 'stop' completed, call release on your engine, and then call Close()

so you would have for code:

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

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

As you're new to coding I wanted to show that way first because you are familiar with the syntax. But the better way for your case would be:

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

This is inlining an event handler instead of using a delegate.