0

I've got a problem with a .NET Core 2.2 console application. I want to start an console app with an static array. This one connects to an TCP/IP partner.

On start up, I start an second console application, which should use the same static array, and the same connection as the first console application. I want to split both apps, cause it is an 'option package'. Both apps are running as background services with timed async functions. Both apps share the same namespace and are configured in the same project. The child app have an dependency of the parent app.

Until now, I can start both apps in the same console (as child-process), but the child-console can't use the static array.

How can I solve it?

Here is my Program.cs Main Method:

    static async Task Main(string[] args) {  
     Portal_Connect.PLC = new Class_PLC[11];     
     if ((Configuration.Diagnostic))           
     {             
      var process = new Process        
      {             
        StartInfo = new ProcessStartInfo           
        {             
          FileName = "dotnet ",
          Arguments = Directory.GetCurrentDirectory() + \\Diagnostic.dll",
          WorkingDirectory = Directory.GetCurrentDirectory(),
          UseShellExecute = false,          
          RedirectStandardOutput = false,            
          RedirectStandardError = false,
          CreateNoWindow = false          
        }                
      };                
    process.Start();
    process.PriorityClass = ProcessPriorityClass.High;                
    process.ProcessorAffinity = (IntPtr)6; 
   }
}
TylerH
  • 20,799
  • 66
  • 75
  • 101
CPolle
  • 1
  • 2
  • I don't think that it is possible, to access one static array and one connection in two different processes. But I may be wrong. – Tolbxela Aug 23 '19 at 10:39
  • Does the second app need to be a console app? how about a class library that shares the same address space as the main app? Pass the connection and the array as argument. – EylM Aug 23 '19 at 10:53
  • Please have a look at https://stackoverflow.com/questions/7894224/sharing-memory-between-two-applications it is not that easy to share memory between two processes, you should consider using threads with locking, but if you need to split it up in two executables then you must use some other logic. – Sebastian Aug 23 '19 at 11:03
  • Well, I can run both application parallel in the same console as background service. Thats the second way to solve my problem. But I want to have two processes. As example, the user wants to stop the second app, so he can open the task manager and stop the process. But I have only one process. The other problem is, how can I configure the background service as the way above (select processor and priorityclass)? – CPolle Aug 26 '19 at 05:25
  • For security reasons you generally can't access the same memory locations in two different processes. So to share data between two processes, you need to implement some sort interprocess communication. For instance memory mapped files, named pipes, ... – derpirscher Oct 08 '21 at 20:00

0 Answers0