/// <summary>
		/// Initializes a new instance of the MargqueeControl class
		/// </summary>
		public MarqueeControl()
		{
			this.InitializeComponent();
			this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
			this.SetStyle(ControlStyles.UserPaint, true);
			this.SetStyle(ControlStyles.DoubleBuffer, true);
			this.SetStyle(ControlStyles.ResizeRedraw, true);			
			this.LoadDefaultImage();								
			this.StepSize = 10;
			this.FrameRate = 33;	
			_thread = new BackgroundThread();
			_thread.Run += new BackgroundThreadStartEventHandler(HandleThreadRun);
		}
		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{			
			if (disposing)
			{
				this.IsScrolling = false;

				if (_thread != null)
				{
					_thread.Dispose();
					_thread = null;
				}

				if (_image != null)
				{
					_image.Dispose();
					_image = null;
				}				
			}
			base.Dispose( disposing );			
		}
        /// <summary>
        /// Asyncronously begins a background thread which maintains a list of AutoUpdateManagers to check for available updates
        /// </summary>
        public void BeginCheckingForUpdates()
        {	           
            // if the thread is null reset it
            if (_thread == null)
            {
                // each instance of the engine will use a background thread to perform it's work
                _thread = new BackgroundThread();
                _thread.Run += new BackgroundThreadStartEventHandler(OnThreadRun);
                _thread.Finished += new BackgroundThreadEventHandler(OnThreadFinished);	
				//_thread.AllowThreadAbortException = true;
            }

            // if the thread is not running
            if (!_thread.IsRunning)
                // start it up
                _thread.Start(true, new object[] {});			
        }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the BackgroundThreadAlreadyExistsException class
 /// </summary>
 /// <param name="thread">The thread that already exists in the collection</param>
 internal BackgroundThreadAlreadyExistsException(BackgroundThread thread) :
     base("The background thread already exists in the collection.")
 {
     _thread = thread;
 }
		/// <summary>
		/// Destroys the specified thread
		/// </summary>
		/// <param name="thread"></param>
		/// <param name="force"></param>
		private void DestroyThread(BackgroundThread thread, bool force)
		{
			try
			{
				if (thread != null)
					if (thread.IsFinished || force)
						thread.Dispose();
			}
			catch(ThreadAbortException)
			{
			}
			catch(Exception ex)
			{
				Log.WriteLine(ex);
			}
		}  
		/// <summary>
		/// Starts a background thread that will monitor the job queue and spawn background threads to process the jobs in the queue
		/// </summary>
		private void StartProcessingJobs()
		{
			_processingThread = new BackgroundThread();
            //_processingThread.AllowThreadAbortException = true;
			_processingThread.Run += new BackgroundThreadStartEventHandler(OnProcessJobs);
			_processingThread.Start(true, new object[] {_maxThreads});			
		}
		/// <summary>
		/// Clean up all of the background threads when the pool is destroyed
		/// </summary>
		protected override void DisposeOfManagedResources()
		{
			// dispose of the processing thread
			_processingThread.Dispose();
			_processingThread = null;

			// dispose of all of the thread pool threads
			this.DestroyThreads(false /* all threads */);
		}
		/// <summary>
		/// Removes a thread from the collection
		/// </summary>
		/// <param name="thread">The thread to remove</param>
		public void Remove(BackgroundThread thread)
		{
			if (this.Contains(thread))
				lock (base.SyncRoot)
				{
					base.InnerList.Remove(thread);
				}
		}
Пример #9
0
		/// <summary>
		/// Starts the server.  Optionally enabling Asp.NET hosting if the host OS supports it.
		/// </summary>
		/// <param name="ep"></param>
		/// <param name="enableAspNetHosting"></param>
		/// <returns></returns>
		public bool Start(IPEndPoint ep, bool enableAspNetHosting)
		{
			try
			{
				_dispatcher = new HttpRequestDispatcher(enableAspNetHosting && this.CanOSSupportAspNet);

				_thread = new BackgroundThread();
				_thread.Run += new BackgroundThreadStartEventHandler(OnThreadRun);
				_thread.Start(true, new object[] { ep });
				_isStarted = true;

				EventManager.Raise<EventArgs>(this.ServerStarted, this, EventArgs.Empty);

				return true;
			}
			catch (Exception ex)
			{
				this.OnException(this, new ExceptionEventArgs(ex));
			}
			return false;
		}
		/// <summary>
		/// Initializes a new instance of the AsyncWindowManager class
		/// </summary>
		/// <param name="provider">The WindowProvider to use to create the window instance</param>
		public AsyncWindowManager(WindowProvider provider)
		{
			if (provider == null)
				throw new ArgumentNullException("provider");

			_provider = provider;
			_type = null;
			_thread = new BackgroundThread();			
			_thread.Run += new BackgroundThreadStartEventHandler(HandleThreadRun);
		}
		/// <summary>
		/// Initializes a new instance of the BackgroundThreadEventArgs class
		/// </summary>
		/// <param name="thread">The background thread about which this event is centered</param>
		public BackgroundThreadEventArgs(BackgroundThread thread) : base()
		{
			_thread = thread;
		}
			/// <summary>
			/// Initializes a new instance of the BackgroundThreadAlreadyExistsException class
			/// </summary>
			/// <param name="thread">The thread that already exists in the collection</param>
			internal BackgroundThreadAlreadyExistsException(BackgroundThread thread) : 
				base("The background thread already exists in the collection.")
			{
				_thread = thread;
			}
//		/// <summary>
//		/// Removes the thread at the specified index
//		/// </summary>
//		/// <param name="index">The index of the thread to remove</param>
//		public void RemoveAt(int index)
//		{
//			lock (base.SyncRoot)
//			{
//				base.InnerList.RemoveAt(index);
//			}
//		}

		/// <summary>
		/// Determines if the collection contains the thread
		/// </summary>
		/// <param name="thread">The thread to look for</param>
		/// <returns></returns>
		public bool Contains(BackgroundThread thread)
		{
			if (thread == null)
				throw new ArgumentNullException("thread");
			
			lock (base.SyncRoot)
			{
				foreach(BackgroundThread t in base.InnerList)
					if (object.Equals(t, thread))
						return true;
				return false;
			}
		}
		/// <summary>
		/// Starts a background thread that will receive messages for the connection
		/// </summary>
		public virtual void BeginReceiving()
		{
			if (this.IsReceiving)
				return;

			_disconnectOnStop = false;
			_stopEvent = new ManualResetEvent(false);
			_thread = new BackgroundThread();
//			_thread.IsBackground = false;
            //_thread.AllowThreadAbortException = true;
			_thread.Run += new BackgroundThreadStartEventHandler(OnReadFromSocket);
			_thread.Start(true /* background thread */, new object[] {});
		}
		/// <summary>
		/// Initializes a new instance of the AsyncWindowManager class
		/// </summary>
		/// <param name="windowType">The Type to use to create the window instance</param>
		public AsyncWindowManager(Type windowType)
		{
			if (windowType == null)
				throw new ArgumentNullException("windowType");

			_provider = null;
			_type = windowType;
			_thread = new BackgroundThread();			
			_thread.Run += new BackgroundThreadStartEventHandler(HandleThreadRun);
		}
		/// <summary>
		/// Stops the background thread that is receiving messages for the connection
		/// </summary>
		/// <param name="disconnect">A flag that indicates whether the connection should be closed</param>
		public virtual void EndReceiving(bool disconnect)
		{
			_disconnectOnStop = disconnect;

			// signal a stop, we might get lucky and ease the thread out
			if (_stopEvent != null)
				_stopEvent.Set();

			// and finally kill the receiving thread
			if (_thread != null) 
			{
				_thread.Dispose();
				_thread = null;				
			}
			_stopEvent = null;
		}
Пример #17
0
 /// <summary>
 /// Initializes a new instance of the BackgroundThreadEventArgs class
 /// </summary>
 /// <param name="thread">The background thread about which this event is centered</param>
 public BackgroundThreadEventArgs(BackgroundThread thread) : base()
 {
     _thread = thread;
 }
Пример #18
0
		/// <summary>
		/// Stops the server (No incoming connections will be accepted while the server is stopped)
		/// </summary>
		/// <returns></returns>
		public bool Stop(bool endCurrentSessions)
		{
			try
			{                       
				if (endCurrentSessions)
					this.EndCurrentSessions();

				if (_thread != null)
				{
					_thread.Dispose();
					_thread = null;
				}

				if (_listeningSocket != null)
				{
					try 
					{
						// shutdown and close the socket
						//             _socket.Shutdown(SocketShutdown.Both);
						_listeningSocket.Close();
					}
					catch(SocketException ex) 
					{
						Debug.WriteLineIf(_verbose, string.Format("An exception was encountered while attempting to shutdown & close the server's listening socket.\n\t{0}", ex.ToString()), TraceCategory);
					}
					_listeningSocket = null;
				}

				_isStarted = false;
				_dispatcher = null;

				EventManager.Raise<EventArgs>(this.ServerStopped, this, EventArgs.Empty);

				return true;
			}
			catch(Exception ex)
			{
				this.OnException(this, new ExceptionEventArgs(ex));
			}        
			return false;
		}
		/// <summary>
		/// Adds a thread to the collection
		/// </summary>
		/// <param name="thread">The thread to add</param>
		public void Add(BackgroundThread thread)
		{
			if (this.Contains(thread))
				throw new BackgroundThreadAlreadyExistsException(thread);
			
			lock (base.SyncRoot)
			{
				base.InnerList.Add(thread);
			}
		}