示例#1
0
        /// <summary>
        /// Detatch from the <see cref="PrecisionInputTimer"/>.
        /// </summary>
        /// <param name="timer">Timer instance to detach from.</param>
        /// <remarks>
        /// Timer reference will be set to <c>null</c> after detatch.
        /// </remarks>
        public static void Detach(ref PrecisionInputTimer timer)
        {
            if ((object)timer != null)
            {
                lock (s_inputTimers)
                {
                    // Verify static frame rate timer for given frames per second exists
                    if (s_inputTimers.ContainsKey(timer.FramesPerSecond))
                    {
                        // Decrement reference count
                        timer.RemoveReference();

                        // If timer is no longer being referenced we stop it and remove it from static collection
                        if (timer.ReferenceCount == 0)
                        {
                            timer.Dispose();
                            s_inputTimers.Remove(timer.FramesPerSecond);
                        }
                    }
                }
            }

            timer = null;
        }