1

I have built a C# voice application that needs to access my microphone for more than one client/server connection at the same time.

The library I'm using only allows my Microphone to be used with one connection at any one time.

Using my microphone on more than one client/server connection at the same time is what I'd like to do.

If I open multiple instances of the app I've built I can use the same Microphone with each app at the same time, resulting in using it on more than one connection.

Great.

But I'd rather not have 3 or 4 instances of my application filling up my desktop, so my thinking was to have a Parent winforms Application which shows child applications within it.

I came across this post How can I run another application within a panel of my C# program?

which seems to be what I was looking for, but...

If I use the example..

        private void button1_Click(object sender, EventArgs e)
    {
        Process p = Process.Start("notepad.exe");
        Thread.Sleep(500); // Allow the process to open it's window
        SetParent(p.MainWindowHandle, panel1.Handle);
    }

    [DllImport("user32.dll")]
    static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
}

Notepad does open up on my form in the panel I've told it to, as expected.

Where as if I change

Process p = Process.Start("notepad.exe");

to

Process p = Process.Start("C:\\Users\\me\\source\\repos\\MyApp\\bin\\Release\\MyApp.exe");

my app is opened as normal outside of my Parent form.

What is this novice missing?

Or am I going about things the wrong way and should be doing something else?

Roo
  • 13
  • 4
  • It's probably because neither the .NET nor your code in your app are [aware of what you are going to put them through](https://blogs.msdn.microsoft.com/oldnewthing/20130412-00/?p=4683). I'm also not sure how this would allow you to better manage microphone connections, how does that "one connection at any one time" restriction actually work if it's not enforced between processes? – GSerg Jan 13 '19 at 23:18
  • I may have confused things by mentioning connection. The connection I refer to is a client server connection. If I create more than one client server connection in the same app, the microphone can only be used with one of the connections at any one time. – Roo Jan 13 '19 at 23:44
  • Have you considered changing your app so only a single instance of it can run at once? – mjwills Jan 13 '19 at 23:58
  • Are you sure your application is finishing its startup within half a second? If not, try increasing 500 to something larger. – BlueMonkMN Jan 14 '19 at 00:46
  • You should use [Process.WaitForInputIdle](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.waitforinputidle) to wait until the new process has created Window handle (not hardcode a time-out). But I'ld read what's in the link GSerg posted. Anyway, you will soon find out yourself what it really implies (when you app starts crashing *for no reason*). – Jimi Jan 14 '19 at 03:05
  • Well thank you for all the comments. I tried the suggestions and still could not get an app I built to display in another app I've built. But due to the comments and advice I've now decided not to go down this route, as although it can be done it's not a good idea to do it. Thanks to all that commented. – Roo Jan 15 '19 at 17:55

0 Answers0