コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        void ThreadExecute(object threadInfoParam)
        {
            ThreadInfo threadInfo = threadInfoParam as ThreadInfo;

            GeneralHelper.AssignThreadCulture();

            while (IsRunning)
            {
                TargetInfo targetInfo = null;
                if (_queue.Count != 0)
                {
                    lock (_queue)
                    {
                        if (_queue.Count > 0)
                        {
                            targetInfo = _queue.Dequeue();
                        }
                    }

                    Interlocked.Exchange(ref _lastQueueItemProcessedMillisecond, GeneralHelper.ApplicationStopwatchMilliseconds);
                }

                if (targetInfo == null)
                {
                    lock (_sleepingThreads)
                    {
                        // Keep this locked.
                        if (IsRunning == false)
                        {// Do not enter sleeping mode, if we are already stopped.
                            return;
                        }
                        _sleepingThreads.Push(threadInfo);
                    }

                    threadInfo.Event.WaitOne();

                    if (threadInfo.MustDispose)
                    {// Instructed to dispose.
                        return;
                    }
                }
                else
                {
                    try
                    {
                        object invokeResult = targetInfo.Invoke();
                    }
                    catch (Exception ex)
                    {
                        InstanceSystem.OperationError(SystemMonitor.ProcessExceptionMessage("[" + _name + "] Thread executed caused an exception ", ex));
                    }
                }
            }
        }