Beispiel #1
0
 public Key Lock(Priority priority = Priority.Normal)
 {
     try
     {
         var hash = HashCreator.GetString(32);
         var e    = new Event()
         {
             Priority = priority,
             Hash     = hash,
             Signal   = new System.Threading.CountdownEvent(1)
         };
         Signal.TryAdd(e);
         e.Signal.Wait();
         return(new Key(priority, hash, Release));
     }
     catch (Exception)
     {
         return(null);
     }
 }
Beispiel #2
0
 public Key LockThrow()
 {
     try
     {
         if (Signal.Count == 0)
         {
             var hash = HashCreator.GetString(32);
             var e    = new Event()
             {
                 Priority = Priority.Critical,
                 Hash     = hash,
                 Signal   = new System.Threading.CountdownEvent(1)
             };
             Signal.TryAdd(e);
             e.Signal.Wait();
             return(new Key(e.Priority, hash, Release));
         }
         return(new Key());
     }
     catch (Exception)
     {
         return(null);
     }
 }