Ejemplo n.º 1
0
		/// <summary>
		/// Try to acquire the token quietly
		/// </summary>
		/// <param name="uniqueIdentifier"></param>
		/// <returns>True if we successfully acquired the token, false otherwise</returns>
		public static bool AcquireTokenQuietly(string uniqueIdentifier)
		{
			Guard.AgainstNull(uniqueIdentifier, "uniqueIdentifier");

			// Each process may only acquire one token
			if (s_fileLock != null)
				return false;

			s_fileLock = SimpleFileLock.Create(uniqueIdentifier + FileExtension);
			return s_fileLock.TryAcquireLock();
		}
Ejemplo n.º 2
0
		/// <summary>
		/// Releases the token when client is finished with it
		/// 
		/// Even though it is a very good idea to release the token when finished with it,
		/// in the event of a crash, the file is released anyway meaning another application can get it.
		/// </summary>
		public static void ReleaseToken()
		{
			if (s_fileLock != null)
			{
				s_fileLock.ReleaseLock();
				s_fileLock = null;
			}
		}