Пример #1
0
 // Removes an action from the thread queue
 public void RemoveExecute(ThreadExecuteMessage msg)
 {
     if (ThreadManager.StopRequested)
     {
         return;
     }
     lock (ExecuteLocker)
     {
         _executeQueue.Remove(msg);
     }
 }
Пример #2
0
 // Enqueue an action on this thread
 public void Execute(ThreadExecuteMessage msg)
 {
     if (ThreadManager.StopRequested)
     {
         return;
     }
     lock (ExecuteLocker)
     {
         _executeQueue.Add(msg);
         AutoResetEvent.Set();
     }
 }
Пример #3
0
        // Execute an action on our thread pool, pushing this action to the top of the queue
        public static void ExecuteNext(ThreadExecuteMessage msg)
        {
            if (StopRequested)
            {
                return;
            }
            lock (ExecuteLocker)
            {
#if DEBUGGING
                TotalJobs++;
#endif
                ExecuteQueue.Insert(0, msg);
            }
        }
Пример #4
0
        public static void ExecuteTimed(string methodName, ThreadExecuteMessage msg)
        {
#if DEBUGGING
            var time = new Stopwatch();
            lock (TimerLocker)
            {
                if (!TimerDictionary.ContainsKey(methodName))
                {
                    TimerDictionary.Add(methodName, new TimerAverageData(new long[0], TimerAverageData.DefaultSamples));
                }
            }
            Execute((container =>
            {
                time.Start();
                container.WaitList.Clear();
                msg(container);
                foreach (var autoResetEvent in container.WaitList)
                {
                    autoResetEvent.WaitOne();
                }
                time.Stop();
                long[] s;
                int ms;
                lock (TimerLocker)
                {
                    s = TimerDictionary[methodName].ElapsedMilliseconds;
                    ms = TimerDictionary[methodName].MaxSamples;
                }
                if (s.Length > ms)
                {
                    var diff = s.Length - ms;
                    var s2 = new long[ms];
                    for (var i = 0; i < s2.Length - 1; i++)
                    {
                        s2[i] = s[diff + i];
                    }
                    s2[s2.Length - 1] = time.ElapsedMilliseconds;
                    s = s2;
                }
                else if (s.Length < ms)
                {
                    var s2 = new long[s.Length + 1];
                    for (var i = 0; i < s.Length; i++)
                    {
                        s2[i] = s[i];
                    }
                    s2[s2.Length - 1] = time.ElapsedMilliseconds;
                    s = s2;
                }
                else
                {
                    for (var i = 0; i < s.Length - 1; i++)
                    {
                        s[i] = s[i + 1];
                    }
                    s[s.Length - 1] = time.ElapsedMilliseconds;
                }
                lock (TimerLocker)
                {
                    TimerDictionary[methodName] = new TimerAverageData(s, ms);
                }
            }));
#else
            Execute(msg);
#endif
        }