Example #1
0
        public HostTerminationReason Run(TimeSpan? watchdogTimeout)
        {
            using (RemoteHostService hostService = new RemoteHostService(watchdogTimeout))
            {
                if (ownerProcess != null)
                {
                    ownerProcess.Exited += delegate { hostService.Dispose(); };
                    ownerProcess.EnableRaisingEvents = true;
                }

                if (ownerProcess == null || !ownerProcess.HasExited)
                {
                    HostServiceChannelInterop.RegisterWithChannel(hostService, serverChannel);
                    hostService.WaitUntilShutdown();
                }

                if (hostService.WatchdogTimerExpired)
                    return HostTerminationReason.WatchdogTimeout;

                if (ownerProcess != null && ownerProcess.HasExited)
                    return HostTerminationReason.Disowned;
            }

            return HostTerminationReason.Disposed;
        }