public void Start()
        {
            lock (this)
            {
                if (hasBeenStarted)
                {
                    throw new InvalidOperationException("Pool has already been started.");
                }

                hasBeenStarted = true;

                // Check to see if there were already items posted to the queue
                // before Start was called.  If so, reset their timestamps to
                // the current time.
                //
                if (requestQueue.Count > 0)
                {
                    ResetWorkRequestTimes();
                }

                for (int n = 0; n < initialThreadCount; n++)
                {
                    ThreadWrapper thread =
                        new ThreadWrapper(this, true, threadPriority,
                                          string.Format("{0} (static)", threadPoolName));
                    thread.Start();
                }

                if (Started != null)
                {
                    Started();                     // TODO: reconsider firing this event while holding the lock...
                }
            }
        }
            public static ThreadWrapper StartNew(Action action)
            {
                var thread = new ThreadWrapper(action);

                thread.Start();
                return(thread);
            }
Exemplo n.º 3
0
        public void Start()
        {
            ICollection <ThreadPoolDelegate> handlers = null;

            Monitor.Enter(_syncLock);
            try
            {
                if (_hasBeenStarted)
                {
                    throw new InvalidOperationException("Pool has already been started.");
                }

                _hasBeenStarted = true;

                /*
                 * Check to see if there were already items posted to the queue
                 * before Start was called.  If so, reset their timestamps to
                 * the current time.
                 */
                if (_requestQueue.Count > 0)
                {
                    ResetWorkRequestTimes();
                }

                for (int n = 0; n < _initialThreadCount; n++)
                {
                    ThreadWrapper thread = new ThreadWrapper(this, true, _threadPriority, string.Format("{0} (static)", _threadPoolName));
                    thread.Start();
                }

                if (Started != null)
                {
                    Delegate[] delegates = Started.GetInvocationList();
                    handlers = new List <ThreadPoolDelegate>(delegates.Length);
                    foreach (ThreadPoolDelegate handler in delegates)
                    {
                        if (handler != null)
                        {
                            handlers.Add(handler);
                        }
                    }
                }
            }
            finally
            {
                Monitor.Exit(_syncLock);
            }

            if (handlers != null)
            {
                foreach (ThreadPoolDelegate handler in handlers)
                {
                    handler();
                }
            }
        }
Exemplo n.º 4
0
        private void lbCreated_DoubleClick(object sender, EventArgs e)
        {
            ThreadWrapper wrapper = lbCreated.SelectedItem as ThreadWrapper;

            wrapper.ChangeDisplayName += Wrapper_ChangeDisplayName;
            wrapper.StateRunning      += Wrapper_StateRunning;

            wrapper.Start();
            lbCreated.Items.Remove(wrapper);
            lbRunAndWait.Items.Add(wrapper);
        }
		public void Start()
		{
			lock (this)
			{
				if (hasBeenStarted)
				{
					throw new InvalidOperationException("Pool has already been started.");
				}

				hasBeenStarted = true;

				// Check to see if there were already items posted to the queue
				// before Start was called.  If so, reset their timestamps to
				// the current time.
				//
				if (requestQueue.Count > 0)
				{
					ResetWorkRequestTimes();
				}

				for (int n = 0; n < initialThreadCount; n++)
				{
					ThreadWrapper thread =
							new ThreadWrapper(this, true, threadPriority,
															string.Format("{0} (static)", threadPoolName));
					thread.Start();
				}

				if (Started != null)
				{
					Started(); // TODO: reconsider firing this event while holding the lock...
				}
			}
		}
Exemplo n.º 6
0
 public virtual void Start()
 {
     _receivingThread.Start();
 }
Exemplo n.º 7
0
 protected override void OnStart()
 {
     _thread.Start();
     StartTimer(1000);
 }
Exemplo n.º 8
0
		public ThreadedNotifier(Listener listener_0, Object notification_1) {
			this.listener = listener_0;
			this.notification = notification_1;
			aThread = new ThreadWrapper(this);
			aThread.Start();
		}
Exemplo n.º 9
0
        public void Start()
        {
            ICollection<ThreadPoolDelegate> handlers = null;

            Monitor.Enter(_syncLock);
            try
            {
                if (_hasBeenStarted)
                {
                    throw new InvalidOperationException("Pool has already been started.");
                }

                _hasBeenStarted = true;

                /*
                 * Check to see if there were already items posted to the queue
                 * before Start was called.  If so, reset their timestamps to
                 * the current time.
                 */
                if (_requestQueue.Count > 0)
                {
                    ResetWorkRequestTimes();
                }

                for (int n = 0; n < _initialThreadCount; n++)
                {
                    ThreadWrapper thread = new ThreadWrapper(this, true, _threadPriority, string.Format("{0} (static)", _threadPoolName));
                    thread.Start();
                }

                if (Started != null)
                {
                    Delegate[] delegates = Started.GetInvocationList();
                    handlers = new List<ThreadPoolDelegate>(delegates.Length);
                    foreach (ThreadPoolDelegate handler in delegates)
                    {
                        if (handler != null)
                            handlers.Add(handler);
                    }
                }
            }
            finally
            {
                Monitor.Exit(_syncLock);
            }

            if (handlers != null)
            {
                foreach (ThreadPoolDelegate handler in handlers)
                {
                    handler();
                }
            }
        }
Exemplo n.º 10
0
 public void Start()
 {
     _listener.Start();
     _threadWrapper.Start();
 }