Domanda

I am trying to create a windows form project, and use speech recognition for the Kinect with the Kinect to Windows SDK. I have

  • the form application project (p1) and
  • the Kinect speech project (p2) which is a command prompt.

I made it a command prompt because it was the easiest way to do things. Anyway, I have read and found two things about this.

1)I found out how to run two projects at the same time in the same solution.

2) I also found out how to add references to get classes from each project to the other.

So, how would I get variables from each project? Just by using project references, or something? P2 can recognize speech and save it to variables, if that counts for anything.

È stato utile?

Soluzione

I made it a command prompt because it was the easiest way to do things.

That sounds like the problem. It sounds like really you should be looking at making your Kinect project a class library. Then you can just call into that class library from the Windows Forms application.

If you want a "test bed" console app, you can always write one which also references the class library.

Note that generally you shouldn't be sharing variables between projects - they're implementation details in most well-encapsulated systems - but you would create types which expose properties, appropriate methods etc.

Altri suggerimenti

Here's a couple of options if I'm understanding you right:

  1. Add those variables to your classes as properties then

    using Solution.MyNamespace; in the class that uses the other project

  2. If you have variables that need to be independent, consider adding a class library project called Abstract or something that both projects reference

I hope this might help, Cheers

Another method is to use named pipes for interprocess communication.

MSDN has the references to use the name pipes API here.

Named pipes are part of the .NET framework and are a reliable method for communication without having to worry about access permissions on files.

To go down the static variable path, you would need to run a single process and turn one project into a dll and load the Program Main manually.

Of course you dont even need to use static variables but use synchronisation on reference variables passed in at load time. I would probably go this method if you didnt need to run two separate processes.

Just depends on what your goal is for having the projects separate processes.

Like @JonSkeet said, create a class library, then you can save the information like this:

    public class SpeechRecognizer
    {
        public List<string> SpeechRecognized = new List<string>
        {

        };

        public void SaveRecognizedSpeech(string foundSpeech)
        {
            SpeechRecognized.Add(foundSpeech);
        }
    }

In code:

        SpeechRecognizer sr = new SpeechRecognizer();
        sr.SaveRecognizedSpeech("blah blah");
        sr.SaveRecognizedSpeech("BLAH BLAH");
        Console.WriteLine("{0}, {1}", sr.SpeechRecognized[0], sr.SpeechRecognized[1]);
        Console.Read();

Oh and to make your whole program know variables(I hope these are both in the same solution!) make them public. Hope this helps!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top