If starting the child process directly from the parent process is acceptable ( UseShellExecute = false ), you can redirect the StandardInput child process and pass an arbitrary data size by throwing it away. Here is an example of passing an array of 100,000 lines and other things, serialization in binary format.
static void Main(string[] args) { if (args.Length == 0) { var exeFilePath = Assembly.GetExecutingAssembly().Location; var psi = new ProcessStartInfo(exeFilePath, "CHILD"); psi.UseShellExecute = false; psi.RedirectStandardInput = true; Console.WriteLine("Parent - Starting child process"); var childProcess = Process.Start(psi); var bf = new BinaryFormatter(); object[] data = Enumerable.Range(1, 100000) .Select(i => (object)$"String-{i}") .Append(13) .Append(DateTime.Now) .Append(new DataTable("Customers")) .ToArray(); Console.WriteLine("Parent - Sending data"); bf.Serialize(childProcess.StandardInput.BaseStream, data); Console.WriteLine("Parent - WaitForExit"); childProcess.WaitForExit(); Console.WriteLine("Parent - Closing"); } else { Console.WriteLine("Child - Started"); var bf = new BinaryFormatter(); Console.WriteLine("Child - Reading data"); var data = (object[])bf.Deserialize(Console.OpenStandardInput()); Console.WriteLine($"Child - Data.Length: {data.Length}"); Console.WriteLine("Child - Closing"); } }
Exit:
Parent - Starting a child process
Baby - Started
Child - Reading Data
Parent - sending data
Parent - WaitForExit
Child - Data. Length: 100003
Baby - Closing
Parent - Closing
This example runs in 6 seconds on my machine.
Theodor zoulias
source share