Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            //This example only references the Proliferate library to use the ExecutableGenerator.
            //Communication is done through WCF.

            var childProcessMainMethod = typeof(ChildProcess).GetMethod("Start");
            var exePath = ExecutableGenerator.Instance.GenerateExecutable(childProcessMainMethod,
                                                                          ExecutableType.Default, "WCFLauncher");
            var startInfo = new System.Diagnostics.ProcessStartInfo(exePath)
            {
                CreateNoWindow = true, UseShellExecute = false
            };
            var w    = System.Diagnostics.Stopwatch.StartNew();
            var proc = System.Diagnostics.Process.Start(startInfo);

            ISomeService pipeProxy = null;
            ChannelFactory <ISomeService> pipeFactory =
                new ChannelFactory <ISomeService>(
                    new NetNamedPipeBinding()
            {
                OpenTimeout = TimeSpan.FromSeconds(3), ReceiveTimeout = TimeSpan.FromSeconds(3)
            },
                    new EndpointAddress("net.pipe://localhost/SomeService"));

            //Don't know a better way to wait for the other end to be ready before calling CreateChannel().
            //So just catch the EndpointNotFoundException and keep retrying.
            while (true)
            {
                try
                {
                    pipeProxy = pipeFactory.CreateChannel();
                    pipeProxy.DoSomethingWithAstring("Hello");
                    break;
                }
                catch (EndpointNotFoundException)
                {}
            }
            Console.WriteLine("Time from process start until response received: " + w.Elapsed.ToString());
            Console.ReadKey();
            pipeProxy.Close();
        }