示例#1
0
 public static void setGlobalEvent(string name, bool defaultValue = true)
 {
     lock (InterProcessEvent._thisLock)
     {
         if (InterProcessEvent._globalEvents == null)
         {
             InterProcessEvent._globalEvents = new Dictionary <string, EventWaitHandle>();
         }
         string text = "Global\\EcoSensorsGlobalEvent-" + name;
         if (!InterProcessEvent._globalEvents.ContainsKey(text))
         {
             EventWaitHandle eventWaitHandle = InterProcessBase.OpenGlobalEvent(text, defaultValue);
             if (eventWaitHandle != null)
             {
                 InterProcessEvent._globalEvents.Add(text, eventWaitHandle);
             }
         }
         if (InterProcessEvent._globalEvents.ContainsKey(text))
         {
             if (defaultValue)
             {
                 InterProcessEvent._globalEvents[text].Set();
             }
             else
             {
                 InterProcessEvent._globalEvents[text].Reset();
             }
         }
     }
 }
示例#2
0
 public static bool getGlobalEvent(string name, bool defaultValue = false)
 {
     lock (InterProcessEvent._thisLock)
     {
         if (InterProcessEvent._globalEvents == null)
         {
             InterProcessEvent._globalEvents = new Dictionary <string, EventWaitHandle>();
         }
         string text = "Global\\EcoSensorsGlobalEvent-" + name;
         if (InterProcessEvent._globalEvents.ContainsKey(text))
         {
             if (InterProcessEvent._globalEvents[text].WaitOne(0))
             {
                 bool result = true;
                 return(result);
             }
         }
         else
         {
             EventWaitHandle eventWaitHandle = InterProcessBase.OpenGlobalEvent(text, defaultValue);
             if (eventWaitHandle != null)
             {
                 InterProcessEvent._globalEvents.Add(text, eventWaitHandle);
                 if (InterProcessEvent._globalEvents[text].WaitOne(0))
                 {
                     bool result = true;
                     return(result);
                 }
             }
         }
     }
     return(false);
 }
示例#3
0
        private bool OpenInterProcessShared()
        {
            Semaphore semaphore = InterProcessBase.OpenGlobalSemaphore(this._semaphoreName, 1, 1);

            if (semaphore == null)
            {
                return(false);
            }
            this._semaphoreEcoInstance = semaphore;
            int num = (int)this._shareMemSize + 8;

            this._semaphoreEcoInstance.WaitOne();
            int num2 = InterProcessBase.SetupShareMemoryWithSercurity(this._strMapFileName, num, ref this._hMapFile, ref this._pMapBuf);

            if (num2 < 0)
            {
                this._semaphoreEcoInstance.Release();
                this._semaphoreEcoInstance = null;
                return(false);
            }
            if (num2 <= 0)
            {
                byte[] array = new byte[num];
                Array.Clear(array, 0, array.Length);
                this.WriteShareArray(0L, array);
                T           t           = (default(T) == null) ? Activator.CreateInstance <T>() : default(T);
                XmlDocument xmlDocument = CustomXmlSerializer.Serialize(t, 8, "SharedObject");
                string      outerXml    = xmlDocument.OuterXml;
                byte[]      bytes       = Encoding.UTF8.GetBytes(outerXml);
                if ((long)bytes.Length < this._shareMemSize)
                {
                    long   value  = (long)bytes.Length;
                    byte[] bytes2 = BitConverter.GetBytes(value);
                    byte[] array2 = new byte[8 + bytes.Length];
                    Array.Copy(bytes2, 0, array2, 0, 8);
                    Array.Copy(bytes, 0, array2, 8, bytes.Length);
                    this.WriteShareArray(0L, array2);
                }
            }
            this._semaphoreEcoInstance.Release();
            return(true);
        }