Example #1
0
		//todo: 添加一个监听线程,每隔一分钟执行一次,检查超过3分钟仍未收到数据的客户端,然后将其关闭
		/// <summary>
		/// 启动管道服务。
		/// </summary>
		public void Start()
		{
			if (this.state == PipeServiceState.Init)
			{
				this.lock4State.EnterWriteLock();
				try
				{
					if (this.state == PipeServiceState.Init)
					{
						this.listener = new PipeServiceListener(this, this.pipeName);
						this.listener.Start();

						this.state = PipeServiceState.Runing;

						this.FireStarted(EventArgs.Empty);
					}
				}
				finally
				{
					this.lock4State.ExitWriteLock();
				}
			}
		}
Example #2
0
		/// <summary>
		/// 停止管道服务。
		/// </summary>
		public void Stop()
		{
			if (this.state == PipeServiceState.Runing)
			{
				this.lock4State.EnterWriteLock();
				try
				{
					if (this.state == PipeServiceState.Runing)
					{
						this.state = PipeServiceState.Stoped; // 立即阻止后续发送请求

						this.listener.Stop();
						this.listener = null;

						this.FireStoped(EventArgs.Empty);
					}
				}
				finally
				{
					this.lock4State.ExitWriteLock();
				}
			}
		}
Example #3
0
		/// <summary>
		/// 初始化管道服务的新实例。
		/// </summary>
		/// <param name="pipeName">管道名称。</param>
		/// <param name="maxNumberOfServerInstances">最大共享实例数。</param>
		/// <param name="listenThreadPriority">监听线程优先级。</param>
		/// <param name="openTimeout">打开连接超时时间。</param>
		/// <param name="sendTimeout">发送数据超时时间。</param>
		/// <param name="receiveTimeout">监听线程等待超时时间。</param>
		public PipeService(string pipeName, int maxNumberOfServerInstances, ThreadPriority listenThreadPriority, int openTimeout, int sendTimeout, int receiveTimeout)
		{
			this.pipeName = pipeName;
			this.maxNumberOfServerInstances = maxNumberOfServerInstances;

			this.listenThreadPriority = listenThreadPriority;

			this.state = PipeServiceState.Init;

			this.openTimeout = openTimeout;
			this.sendTimeout = sendTimeout;
			this.receiveTimeout = receiveTimeout;

			this.channelManager = new PipeServiceChannelManager(this.pipeName);
		}