System.IO.Stream.Stream.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
		BeginRead (byte [] buffer, int offset, int count, AsyncCallback callback, object state)
		{
			if (!CanRead)
				throw new NotSupportedException ("This stream does not support reading");

			// Creating a class derived from Stream that doesn't override BeginRead
			// shows that it actually calls Read and does everything synchronously.
			// Just put this in the Read override:
			//	Console.WriteLine ("Read");
			// 	Console.WriteLine (Environment.StackTrace);
			//	Thread.Sleep (10000);
			//	return 10;

			StreamAsyncResult result = new StreamAsyncResult (state);
			try {
				int nbytes = Read (buffer, offset, count);
				result.SetComplete (null, nbytes);
			} catch (Exception e) {
				result.SetComplete (e, 0);
			}

			if (callback != null)
				callback (result);

			return result;
		}