Esempio n. 1
0
 public void Set(string sData)
 {
     lock (Locker.Get("DDTSBuffer"))
     {
         if (DDTSBuffer.ContainsKey(DateTime.Now))
         {
             DDTSBuffer.Add(DDTSBuffer.Last().Key.AddMilliseconds(1), sData);
         }
         else
         {
             DDTSBuffer.Add(DateTime.Now, sData);
         }
     }
 }
Esempio n. 2
0
 public void Set(string sData)
 {
     lock (Locker.Get("DDTSBuffer"))
     {
         DDTSBuffer.Add(TickTime.Now, sData);
     }
 }
Esempio n. 3
0
        public static ThreadedDictionary <K, ThreadedDictionary <K2, V2> > ToThreadedDictionary <K, K2, V2>(Dictionary <K, Dictionary <K2, V2> > D2KV)
        {
            ThreadedDictionary <K, ThreadedDictionary <K2, V2> > TD2KV = new ThreadedDictionary <K, ThreadedDictionary <K2, V2> >();

            foreach (KeyValuePair <K, Dictionary <K2, V2> > KVP2 in D2KV)
            {
                TD2KV.Add(KVP2.Key, (ThreadedDictionary <K2, V2>)KVP2.Value);
            }

            return(TD2KV);
        }
Esempio n. 4
0
        public ThreeState Get(string ID)
        {
            ID = ThreadedThreeStates.CheckID(ID);

            lock (Lock)
            {
                if (!Data.ContainsKey(ID))
                {
                    if (indexer >= _MaxStates)
                    {
                        throw new Exception("ThreadedThreeStates.Get exception, states limit exhausted, maximum of " + _MaxStates + "states");
                    }

                    Data.Add(ID, indexer, true);
                    States[indexer] = ThreeState.Null;
                    ++indexer;
                }

                return(States[Data[ID]]);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Sets Date point
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public bool DateSet(string ID = null)
        {
            ID = this.ValidateID(ID);

            if (DataDate.ContainsKey(ID))
            {
                DataDate[ID] = DateTime.Now;
            }
            else
            {
                DataDate.Add(ID, DateTime.Now);
            }

            return(false);
        }
Esempio n. 6
0
        public object Get(string ID = null)
        {
            ID = ThreadedLocker.CheckID(ID);

            lock (Lock)
            {
                if (!Data.ContainsKey(ID))
                {
                    if (lockIndexer >= _MaxLocks)
                    {
                        throw new Exception("ThreadedLocker.Get exception, locks limit exhausted, maximum of " + _MaxLocks + "locks");
                    }

                    Data.Add(ID, lockIndexer, true);
                    Locks[lockIndexer] = new object();
                    ++lockIndexer;
                }

                return(Locks[Data[ID]]);
            }
        }
Esempio n. 7
0
        public bool Set(string sKey, T tValue, bool bUpdate = true)
        {
            if (sKey == null)
            {
                return(false);
            }

            if (!this.Contains(sKey))
            {
                Data.Add(sKey, tValue);
                return(true);
            }

            if (bUpdate)
            {
                Data[sKey] = tValue;
                return(true);
            }

            return(false);
        }
Esempio n. 8
0
        public bool RunF <TResult>(Expression <Func <TResult> > expression, string ID, int delay, bool Exceptions, bool waitForAccess, bool invoke)
        {
            if (expression == null)
            {
                return(false);
            }


            while (MaxThreadsCount < TDSThreads.Count)
            {
                if (!waitForAccess)
                {
                    return(false);
                }
                ;

                Thread.Sleep(AccessWait);
                this.TerminateAllCompleated();
            }

            if (System.String.IsNullOrEmpty(ID))
            {
                ID = Expressions.nameofFull <TResult>(expression);
            }
            if (IsAlive(ID))
            {
                return(false);
            }
            try
            {
                lock (Locker.Get("Run"))
                {
                    this.Terminate(ID);

                    Func <TResult> Function = expression.Compile();
                    Results.Add(ID, default(TResult));

                    if (Exceptions)
                    {
                        if (invoke)
                        {
                            TDSThreads.Add(ID, new Thread(() => { if (delay > 0)
                                                                  {
                                                                      Thread.Sleep(delay);
                                                                  }
                                                                  TResult result = Function.Invoke(); Results[ID] = result; }));
                        }
                        else
                        {
                            TDSThreads.Add(ID, new Thread(() => { if (delay > 0)
                                                                  {
                                                                      Thread.Sleep(delay);
                                                                  }
                                                                  TResult result = Function(); Results[ID] = result; }));
                        }
                    }
                    else
                    {
                        if (invoke)
                        {
                            TDSThreads.Add(ID, new Thread(() => { try { if (delay > 0)
                                                                        {
                                                                            Thread.Sleep(delay);
                                                                        }
                                                                        TResult result = Function.Invoke(); Results[ID] = result; } catch { } }));
                        }
                        else
                        {
                            TDSThreads.Add(ID, new Thread(() => { try { if (delay > 0)
                                                                        {
                                                                            Thread.Sleep(delay);
                                                                        }
                                                                        TResult result = Function(); Results[ID] = result; } catch { } }));
                        }
                    }


                    TDSThreads[ID].Priority     = Priority;
                    TDSThreads[ID].IsBackground = true;
                    TDSThreads[ID].Start();
                }
            }
            finally
            {
            }

            return(true);
        }
Esempio n. 9
0
        public bool RunF <TResult>(Expression <Func <TResult> > expression, string ID, int delay, bool Exceptions, bool waitForAccess)
        {
            if (expression == null)
            {
                return(false);
            }


            while (MaxThreadsCount < TDSThreads.Count)
            {
                if (!waitForAccess)
                {
                    return(false);
                }

                Thread.Sleep(AccessWait);
                this.TerminateAllCompleated();
            }

            if (ID.IsNullOrEmpty())
            {
                ID = Expressions.nameofFull <TResult>(expression);
            }

            if (IsAlive(ID))
            {
                return(false);
            }

            try
            {
                if (!LockerRun.EnterWait())
                {
                    return(false);
                }

                this.Terminate(ID);

                Func <TResult> Function = expression.Compile();
                Results.Add(ID, default(TResult), true);

                if (Exceptions)
                {
                    TDSThreads.Add(ID, new Thread(() => { if (delay > 0)
                                                          {
                                                              Thread.Sleep(delay);
                                                          }
                                                          TResult result = Function(); Results[ID] = result; }), true);
                }
                else
                {
                    TDSThreads.Add(ID, new Thread(() => { try { if (delay > 0)
                                                                {
                                                                    Thread.Sleep(delay);
                                                                }
                                                                TResult result = Function(); Results[ID] = result; } catch { } }), true);
                }


                TDSTMFlags.Add(ID, new ThreadedMethodFlags {
                    IsAborting = false
                }, true);

                TDSThreads[ID].Priority     = Priority;
                TDSThreads[ID].IsBackground = true;
                TDSThreads[ID].Start();
            }
            finally
            {
                LockerRun.Exit();
            }

            return(true);
        }
Esempio n. 10
0
 /// <summary>
 /// Sets Date point
 /// </summary>
 /// <param name="ID"></param>
 /// <returns></returns>
 public void DateSet(string ID)
 {
     DataDate.Add(this.ValidateID(ID), DateTime.Now, true);
 }