예제 #1
0
        /// <summary>
        /// Initialize a new ThreadHandle that will start a new Thread.
        /// If memory parameter is 0 this handle will manage the thread that called the constructor.
        /// </summary>
        public ThreadHandle(long memory)
        {
            // initialize the required parameters
            Needles = new ArrayRig <Needle>();

            Handles.Take();
            if (memory == 0)
            {
                Thread            = Thread.CurrentThread;
                Thread.Priority   = ThreadPriority.AboveNormal;
                ThreadHandle.Main = this;
                Thread.Name       = "Main";
            }
            else
            {
                Thread      = new Thread(new ThreadStart(Run), (int)memory);
                Thread.Name = (Handles.Item.Count + 1).ToString();
            }

            Id = Thread.ManagedThreadId;
            Handles.Item.Add(this);
            _handleMap.TakeItem()[Id] = this;

            _handleMap.Release();
            Handles.Release();

            _iteration = -1;
            _index     = -1;
        }
예제 #2
0
 /// <summary>
 /// On a thread handle being removed.
 /// </summary>
 protected void OnRemove(ThreadHandle handle)
 {
     _items.Remove(handle.Id);
 }
예제 #3
0
        //-------------------------------------------//

        /// <summary>
        /// On a new thread handle.
        /// </summary>
        protected void OnAdd(ThreadHandle handle)
        {
            _items[handle.Id] = _getItem == null ? default(T) : _getItem.Run();
        }