Esempio n. 1
0
        /// <summary>
        /// Creates a process that periodically calls the given session manager's CleanUpOldSessions()
        /// method at the specified interval.
        /// </summary>
        /// <typeparam name="TSession">The type of session used by the given session manager.</typeparam>
        /// <param name="sessionManager">The session manager.</param>
        /// <param name="interval">The interval at which to schedule clean-ups.</param>
        /// <returns>The Timer threading object associated with the periodic clean-up process.</returns>
        public static Timer CreateCleanUpTimer <TSession>(this ISessionManager <TSession> sessionManager, TimeSpan interval)
            where TSession : ISession
        {
            if (interval < TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException("interval", "Clean up interval must be positive.");
            }

            return(new Timer(state => sessionManager.CleanUpOldSessions(), null, interval, interval));
        }