2

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.

Liam McInroy
  • 4,339
  • 5
  • 32
  • 53
pjrader1
  • 491
  • 7
  • 22
  • 1
    do you want to use shared variables between both projects? – Sleiman Jneidi Jun 15 '12 at 05:44
  • @sleiman Yes, I do want to share variables, so I can get info from one project to the other. – pjrader1 Jun 15 '12 at 05:56
  • 1
    If you want to create single instance of object shared between two projects use Singleton pattern, but you should be aware of its pros and cons, Read it [Here](http://stackoverflow.com/questions/228164/on-design-patterns-when-to-use-the-singleton) and [here](http://stackoverflow.com/questions/604844/pros-and-cons-of-using-singleton-pattern-in-dal) – MSUH Jun 15 '12 at 06:03
  • 1
    Are you using two projects in the same solution? or two different solutions? – Liam McInroy Jun 15 '12 at 20:10

4 Answers4

7

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.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • I never thought of trying a class library. Ill give it a go. I tried (and miserably failed) to put my Kinect methods into a class and executing a command, but then I realized that the console has a loop, where the class doesn't. I just want to find the easiest way. – pjrader1 Jun 15 '12 at 06:08
  • 1
    @cakeisajoke: You would quite possibly want to put that looping within the class library, running it from a separate thread. It's hard to know without seeing the code though. – Jon Skeet Jun 15 '12 at 06:09
  • 1
    Oh no! Jon skeet is starting Kinect?!?!?!? I will gain no furthur rep from this point on :(. +1 as this is what I did do for speech and another project combined – Liam McInroy Jun 15 '12 at 13:57
  • @OutlawLemur: I know absolutely nothing about the Kinect. It just seemed an obvious answer to give :) – Jon Skeet Jun 15 '12 at 14:01
  • @JonSkeet Oh that's a relieve ;). It is an interesting field though – Liam McInroy Jun 15 '12 at 14:28
2

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

onetwopunch
  • 3,279
  • 2
  • 29
  • 44
0

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.

Gerard Sexton
  • 3,114
  • 27
  • 36
0

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!

Liam McInroy
  • 4,339
  • 5
  • 32
  • 53