System.IO.MemoryStream.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) =>
            TaskToApm.Begin(ReadAsync(buffer, offset, count, CancellationToken.None), callback, state);

Usage Example

Exemple #1
0
        public void BeginRead_should_be_callable_indirectly()
        {
            using (new IndirectionsContext())
            {
                // Arrange
                PStream.BeginReadByteArrayInt32Int32AsyncCallbackObject().Body = (@this, _buffer, offset, count, callback, state) => 
                    IndirectionsContext.ExecuteOriginal(() => @this.BeginRead(_buffer, offset, 42, callback, state));

                var buffer = new byte[256];
                for (int i = 0; i < buffer.Length; i++)
                    buffer[i] = (byte)i;


                using (var ms = new MemoryStream(buffer))
                {
                    // Act
                    var _buffer = new byte[1024];
                    var ar = ms.BeginRead(_buffer, 0, _buffer.Length, null, null);
                    var actual = ms.EndRead(ar);

                    // Assert
                    Assert.AreEqual(42, actual);
                }
            }
        }