Esempio n. 1
0
        private void LifetimeWatcher()
        {
            try
            {
                bool signaled = false;
                while (!signaled)
                {
                    // Wait for either a signal or a time-out
                    signaled = _lifetimeSignal.WaitOne(IdleTimeInSeconds * 1000);

                    if (!signaled)
                    {
                        DateTime oldestActivityTime = DateTime.Now.AddSeconds(-IdleTimeInSeconds);

                        RemoteServerConnection[] connections = _remoteServer.GetCurrentConnections();
                        for (int index = 0; index < connections.Length; index++)
                        {
                            if (connections[index].LastActivityTime < oldestActivityTime)
                            {
                                try
                                {
                                    // Connection has been idle for longer than the activity time, kill it
                                    _remoteServer.Server.LogMessage(String.Format("Connection relinquished due to inactivity: ConnectionName={0}, HostName={1}, LastActivity={2}", connections[index].ConnectionName, connections[index].HostName, connections[index].LastActivityTime.ToShortTimeString()));
                                    _remoteServer.Relinquish(connections[index]);
                                }
                                catch (Exception exception)
                                {
                                    _remoteServer.Server.LogError(exception);
                                }
                            }
                        }
                    }
                }

                // The keep alive processing is complete.  Clean up...
                lock (_lifetimeSyncHandle)
                {
                    _lifetimeSignal.Close();
                    _lifetimeSignal = null;
                }
            }
            catch
            {
                // Don't allow exceptions to go unhandled, the framework will terminate the server.
            }
        }