1

I'm surching for a way to communicate betwen two local c# Programms in an effective and very fast way. The best would be if it is possible to trigger a method of the "main" program with the second one and recive the result like a getter and setter. is there a something i that dosnt need 2 install a local server or something like that?

if more details needed. I am writing a little Programm for some Audio management and have a Device that has some dials and and an SDK for Plugins. The plan is to change some settings in the Programm if i have the Device connected to my PC and show some of the results on it. And the reason for not dooing all of it as a Plugin is that the Programm should be able to run on its own.

i would be glad for some simple exaples to start with.

MaZZe
  • 11
  • 1
  • Does this answer your question? [What is the simplest method of inter-process communication between 2 C# processes?](https://stackoverflow.com/questions/528652/what-is-the-simplest-method-of-inter-process-communication-between-2-c-sharp-pro) – TJ Rockefeller Feb 10 '22 at 13:42
  • WCF has not been ported to .NET Core. The modern way is [gRPC](https://grpc.io/docs/languages/csharp/quickstart/) as propagated by [Microsoft](https://learn.microsoft.com/en-us/aspnet/core/grpc/basics?view=aspnetcore-6.0). – Olivier Jacot-Descombes Feb 10 '22 at 13:53
  • The easiest way is to just use a database like Sql Server Express. – Charles Feb 10 '22 at 13:53

1 Answers1

0

I've successfully used Unosquare's Embed.IO (no affiliation) before now to make a program host a small web server. You can see examples of setup on their home page

You might set up some AudioController class:

class AudioController: WebApiController{
    
    [Route(HttpVerbs.Get, "/api/samplerate/{rate}")]
    public object SetSampleRate(int rate)
    {
       //set the rate?
       Properties.Settings.Default.SamplingRate = rate;

       return true;   
    }
    
}

And then in the client you might poke that endpoint:

var wc = new WebClient(); 
wc.DownloadString("http://localhost:1234/api/samplerate/44100");

Perhaps you want a more complex request object:

class RecorderSettings{
    public int SampleRate{get;set;}
    public int Bits{get;set;}
}

class AudioController: WebApiController{
    
    [Route(HttpVerbs.Post, "/api/setMulti")]
    public async Task<object> SetMultiple()
    {
       var x = await HttpContext.GetRequestDataAsync<RecorderSettings>();

       Properties.Settings.Default.SamplingRate = x.SampleRate;
       Properties.Settings.Default.Bitness = x.Bits;

       return ...;   
    }
    
}

And some client poking it with json:

     //client is some static HttpClient

     HttpResponseMessage response = await client.PostAsync(
       "http://localhost:1234/api/setMulti",
       new StringContent(
         JsonConvert.Serialize(new { SampleRate = 44100, Bits = 16}),
         Encoding.UTF8, 
         MediaTypeNames.Application.Json
       )
     );
Caius Jard
  • 72,509
  • 5
  • 49
  • 80
  • Thanks for your answer, seems like i have to try this way for that. I was hoping for a way without a local web server. Just for multiple triggers with some int returns. Because delay is a thing with what i am planning in the long term with it. – MaZZe Mar 03 '22 at 20:22
  • "Go for the simple solution, not the perfect one" – Caius Jard Mar 08 '22 at 07:03