Exemplo n.º 1
0
        /// <summary>
        /// 프레임워크 내부적으로 사용되는 메서드
        /// </summary>
        /// <param name="scheduler"></param>
        public void Run(Worker worker)
        {
            _worker = worker;
            Thread.Value = this;
            if (_enumerator == null)
                _enumerator = _func();

            bool end = Loop(worker);

            Thread.Value = null;

            if (_parent != null && end)
                Run(_parent);
        }
Exemplo n.º 2
0
 private bool Loop(Worker worker)
 {
     if(_enumerator.MoveNext())
     {
         if (_enumerator.Current is Microthread)
             worker.RunMicrothread(_enumerator.Current as Microthread);
         if (_enumerator.Current is NoneYield)
             return true;
         return false;
     }
     return true;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Worker Therad의 갯수와 Background 여부를 지정하는 메소드
        /// 단, SetThreadCount 메소드는 Netronics가 시작되기전에 호출하여야 함
        /// </summary>
        /// <param name="count">Thread 갯수</param>
        /// <param name="background">Background 여부</param>
        public void SetThreadCount(int count, bool background = false)
        {
            if (count < 1)
                return;

            //모니터링 스래드가 존재하면 종료
            try
            {
                if (_monitoringThread != null)
                    _monitoringThread.Abort();
                _monitoringThread = null;
            }
            catch (ThreadStateException)
            {
            }

            if (_workers.Length > count) //기존 Worker Thread 수보다 설정할 갯수가 적으면 삭제
            {
                for (int i = _workers.Length - 1; i >= count; i--)
                {
                    _workers[i]._run = false;
                    _workers[i] = null;
                }

                var temp = new Worker[count];

                Array.Copy(_workers, temp, count);

                _workers = temp;
            }
            else if (_workers.Length < count) //기존 Worker Thread 수보다 설정할 갯수가 많으면 추가
            {
                var temp = new Worker[count];

                Array.Copy(_workers, temp, _workers.Length);

                for (int i = _workers.Length; i < temp.Length; i++)
                    temp[i] = new Worker();

                _workers = temp;
            }

            foreach (Worker worker in _workers)
            {
                worker.SetBackground(background);
            }

            if (_monitoringThread == null)
            {
                _monitoringThread = new Thread(Monitoring);
                _monitoringThread.Start();
            }
        }