示例#1
0
        public void WaitConnected()
        {
            // If we don't wait here, we'll sometimes get stuck in doNothing(). Make sure the
            // server has had time to start... This only seems to be needed when starting a
            // server in a different process, though.
            var loadedTime = DateTime.UtcNow - serverLoadedTime;
            var waitTime   = WAIT_TIME_BEFORE_CONNECTING - (int)loadedTime.TotalMilliseconds;

            if (waitTime > 0)
            {
                Thread.Sleep(waitTime);
            }

            var startTime = DateTime.UtcNow;

            while (true)
            {
                try {
                    service.DoNothing();
                    break;
                }
                catch (RemotingException) {
                    // Couldn't connect
                }
                var elapsedTime = DateTime.UtcNow - startTime;
                if (elapsedTime.TotalMilliseconds >= MAX_CONNECT_WAIT_TIME_MS)
                {
                    throw new ApplicationException("Could not connect to server");
                }
                Thread.Sleep(20);
            }
        }