Beispiel #1
0
        private void testCMCore(int s, int t)
        {
            bool i = false;

            try
            {
                if (t == 0 ? myMutex.WaitForMutex(): myMutex.WaitForMutex(t))
                {
                    i = true;
                    while (true)
                    {
                        CrestronConsole.PrintLine("*** Mutex {0} Running ***", s);
                    }
                }
                else
                {
                    i = false;
                    CrestronConsole.PrintLine("*** Mutex {0} Timed Out {1}ms ***", s, t);
                }
            }
            catch (Exception e)
            {
                CrestronConsole.PrintLine("*** Error: {0} - {1} ***", s, e.Message);
            }
            finally
            {
                if (i)
                {
                    myMutex.ReleaseMutex();
                }
            }
        }
        void OnTimer(Object o)
        {
            bMutex.WaitForMutex();
//            CrestronConsole.PrintLine("Ping!");
            if (Buffer.Length > 0)
            {
                try
                {
                    {
                        int l = (Buffer.Length > nChunk_Size) ? nChunk_Size : Buffer.Length;

                        String s = Buffer.ToString(0, l);
                        Buffer.Remove(0, l);
//                        CrestronConsole.PrintLine("Dechunk {0}", s);
                        if (OnChunk != null)
                        {
                            OnChunk(s);
                        }
                    }
                }
                catch (Exception e)
                {
                    CrestronConsole.PrintLine(e.Message);
                    CrestronConsole.PrintLine(e.StackTrace);
                }
            }
            bMutex.ReleaseMutex();
        }
Beispiel #3
0
 /// <summary>
 /// Attempts to aquire a lock to access the section of code (non-blocking).
 /// (Note: You must check the returned LockToken in this case to ensure that
 /// the lock was actually aquired.)
 /// </summary>
 /// <returns>LockToken object</returns>
 public bool TryAquireLock(out LockToken lockToken)
 {
     if (_mutex.WaitForMutex(1))
     {
         lockToken = new LockToken(this);
         return(true);
     }
     lockToken = default(LockToken);
     return(false);
 }
 void SendTelegramToKnx()
 {
     if (SendQueue.Count > 0)
     {
         bMutex.WaitForMutex();
         try
         {
             string sout = SendQueue.Dequeue();
             if ((!string.IsNullOrEmpty(sout)) && (OnSend != null))
             {
                 OnSend(sout);
             }
         }
         catch (Exception e)
         {
             Logger.Log("SendTelegramToKnx: {0}", e.Message);
         }
         finally
         {
             bMutex.ReleaseMutex();
         }
     }
 }
Beispiel #5
0
 protected override bool WaitOneInternal(int timeout)
 {
     return(cm.WaitForMutex(timeout));
 }