Exemple #1
0
        /// <summary>
        /// Attempts to obtain the lock for this instance, at most, waiting the length of
        /// the <c>timeoutMs</c> specified.
        /// </summary>
        /// <param name="timeoutMs">The maximum time to wait before failing, in milliseconds.</param>
        /// <returns>
        /// <c>true</c> if the thread obtains the lock, or <c>false</c> if the timeout occurs
        /// before successfully obtaining the lock.
        /// </returns>
        public bool TryLock(int timeoutMs)
        {
            bool success = _monitor.TryEnter(timeoutMs);

            if (success)
            {
                _lockCount++;
                _lockHolder = Thread.CurrentThread;
            }
            return(success);
        }