System.Threading.Monitor.Monitor_try_enter C# (CSharp) Method

Monitor_try_enter() private method

private Monitor_try_enter ( object obj, int ms ) : bool
obj object
ms int
return bool
		private extern static bool Monitor_try_enter(object obj, int ms);

Usage Example

示例#1
0
 /// <summary>Attempts, for the specified number of milliseconds, to acquire an exclusive lock on the specified object.</summary>
 /// <returns>true if the current thread acquires the lock; otherwise, false.</returns>
 /// <param name="obj">The object on which to acquire the lock. </param>
 /// <param name="millisecondsTimeout">The number of milliseconds to wait for the lock. </param>
 /// <exception cref="T:System.ArgumentNullException">The <paramref name="obj" /> parameter is null. </exception>
 /// <exception cref="T:System.ArgumentOutOfRangeException">
 ///   <paramref name="millisecondsTimeout" /> is negative, and not equal to <see cref="F:System.Threading.Timeout.Infinite" />. </exception>
 /// <filterpriority>1</filterpriority>
 public static bool TryEnter(object obj, int millisecondsTimeout)
 {
     if (obj == null)
     {
         throw new ArgumentNullException("obj");
     }
     if (millisecondsTimeout == -1)
     {
         Monitor.Enter(obj);
         return(true);
     }
     if (millisecondsTimeout < 0)
     {
         throw new ArgumentException("negative value for millisecondsTimeout", "millisecondsTimeout");
     }
     return(Monitor.Monitor_try_enter(obj, millisecondsTimeout));
 }