コード例 #1
0
 /// <summary>
 /// Defeats the protocol by removing the file and replacing it with one that contains the
 /// new process identifier -
 /// </summary>
 /// <param name="sem">A FileSempahore</param>
 /// <returns>True if successfull.</returns>
 private static bool ForceLock(ref FileSemaphore sem)
 {
     if (sem.RemoveLock() == false)
     {
         return(false);
     }
     return(Lock(ref sem));
 }
コード例 #2
0
        /// <summary>
        /// Lock a semaphore file. You can only UnLock a semaphore that either does not exists, or that your process
        /// has previously Locked.
        /// </summary>
        /// <param name="sem">A semaphore file (context)</param>
        /// <returns>True if the semaphore file was released.</returns>
        public static bool UnLock(ref FileSemaphore sem)
        {
            // STEP: If the semaphore file is not there, then the resource is unlocked.
            if (sem.IsLocked() == false)
            {
                return(true);
            }

            // STEP: The general public can ONLY remove a semaphore file IF it is theirs
            if (sem.iSemCode == sem.GetSemaphore())
            {
                return(sem.RemoveLock());
            }

            // Otherwise the user CANNOT unlock it!
            return(false);
        }
コード例 #3
0
 /// <summary>
 /// Should not be used. Here just in case things go VERY wrong.
 /// </summary>
 /// <returns></returns>
 public bool RemoveLocks()
 {
     return(fSem.RemoveLock());
 }