System.IO.Pipes.PipeStream.BeginRead C# (CSharp) Méthode

BeginRead() public méthode

public BeginRead ( byte buffer, int offset, int count, AsyncCallback callback, object state ) : IAsyncResult
buffer byte
offset int
count int
callback AsyncCallback
state object
Résultat IAsyncResult
        public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
        {
            if (_isAsync)
                return TaskToApm.Begin(ReadAsync(buffer, offset, count, CancellationToken.None), callback, state);
            else
                return base.BeginRead(buffer, offset, count, callback, state);
        }

Same methods

PipeStream::BeginRead ( byte buffer, int offset, int count, System callback, object state ) : System.IAsyncResult

Usage Example

		public static int Read(PipeStream stream, byte[] buffer, int offset, int count, bool isAsync, TimeoutHelper timeoutHelper)
		{
			// 异步时,使用异步方式读取数据
			if (isAsync)
			{
				IAsyncResult asyncResult = stream.BeginRead(buffer, offset, count, null, null);

				// 等待 timeoutHelper 计算后的剩余时间,如果在这段时间内没有读到数据,那么将直接返回,这时,由于没有读到数据,返回的数据长度为 0
				asyncResult.AsyncWaitHandle.WaitOne(timeoutHelper == null ? 60000 : (int)timeoutHelper.RemainingTime().TotalMilliseconds);

				if (asyncResult.GetType() == pipeStreamAsyncResultType)
				{
				    pipeStreamAsyncResult_waitHandle.SetValue(asyncResult, null);
				}

				return stream.EndRead(asyncResult);
			}

			// 使用系统内置的方式进行同步阻塞式读取,该方法直到读取到数据才返回
			return stream.Read(buffer, offset, count);
		}
All Usage Examples Of System.IO.Pipes.PipeStream::BeginRead