Stream.BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object) 메서드
정의
비동기 쓰기 작업을 시작합니다.Begins an asynchronous write operation. 대신 WriteAsync(Byte[], Int32, Int32)를 사용하세요.(Consider using WriteAsync(Byte[], Int32, Int32) instead.)
public:
virtual IAsyncResult ^ BeginWrite(cli::array <System::Byte> ^ buffer, int offset, int count, AsyncCallback ^ callback, System::Object ^ state);
public virtual IAsyncResult BeginWrite (byte[] buffer, int offset, int count, AsyncCallback? callback, object? state);
public virtual IAsyncResult BeginWrite (byte[] buffer, int offset, int count, AsyncCallback callback, object state);
public virtual IAsyncResult BeginWrite (byte[] buffer, int offset, int count, AsyncCallback callback, object? state);
abstract member BeginWrite : byte[] * int * int * AsyncCallback * obj -> IAsyncResult
override this.BeginWrite : byte[] * int * int * AsyncCallback * obj -> IAsyncResult
Public Overridable Function BeginWrite (buffer As Byte(), offset As Integer, count As Integer, callback As AsyncCallback, state As Object) As IAsyncResult
매개 변수
- buffer
- Byte[]
데이터를 쓸 버퍼입니다.The buffer to write data from.
- offset
- Int32
쓰기를 시작할 buffer
의 바이트 오프셋입니다.The byte offset in buffer
from which to begin writing.
- count
- Int32
쓸 최대 바이트 수입니다.The maximum number of bytes to write.
- callback
- AsyncCallback
쓰기가 완료되면 호출되는 선택적 비동기 콜백입니다.An optional asynchronous callback, to be called when the write is complete.
- state
- Object
다른 요청에서 특정 비동기 쓰기 요청을 구별하는 사용자 제공 개체입니다.A user-provided object that distinguishes this particular asynchronous write request from other requests.
반환
보류 중인 비동기 쓰기를 나타내는 IAsyncResult
입니다.An IAsyncResult
that represents the asynchronous write, which could still be pending.
예외
스트림의 끝을 넘어 비동기 쓰기를 시도했거나 디스크 오류가 발생한 경우Attempted an asynchronous write past the end of the stream, or a disk error occurs.
하나 이상의 인수가 잘못된 경우One or more of the arguments is invalid.
스트림이 닫힌 후에 메서드가 호출되었습니다.Methods were called after the stream was closed.
현재 Stream
구현이 쓰기 작업을 지원하지 않는 경우The current Stream
implementation does not support the write operation.
설명
.NET Framework 4 및 이전 버전에서 비동기 I/O 작업을 구현하려면 BeginWrite 및 EndWrite와 같은 메서드를 사용해야 합니다.In the .NET Framework 4 and earlier versions, you have to use methods such as BeginWrite and EndWrite to implement asynchronous I/O operations. 이러한 메서드는 여전히에서 사용 하 여 레거시 코드를 지원할 수 있지만,,, 등의 .NET Framework 4.5.NET Framework 4.5 새로운 비동기 메서드는 ReadAsync WriteAsync CopyToAsync FlushAsync 비동기 i/o 작업을 보다 쉽게 구현 하는 데 도움이 됩니다.These methods are still available in the .NET Framework 4.5.NET Framework 4.5 to support legacy code; however, the new async methods, such as ReadAsync, WriteAsync, CopyToAsync, and FlushAsync, help you implement asynchronous I/O operations more easily.
스트림에서의 기본 구현은 BeginWrite
Write 메서드를 동기적으로 호출 합니다. 즉,가 Write
일부 스트림에서 차단 될 수 있습니다.The default implementation of BeginWrite
on a stream calls the Write method synchronously, which means that Write
might block on some streams. 그러나와 같은 클래스의 인스턴스 FileStream
NetworkStream
는 인스턴스가 비동기식으로 열린 경우 비동기 작업을 완벽 하 게 지원 합니다.However, instances of classes such as FileStream
and NetworkStream
fully support asynchronous operations if the instances have been opened asynchronously. 따라서에 대 한 호출은 BeginWrite
이러한 스트림에서 차단 되지 않습니다.Therefore, calls to BeginWrite
will not block on those streams. BeginWrite
비동기 대리자를 사용 하 여 비동기 동작을 제공 하는를 재정의할 수 있습니다.You can override BeginWrite
(by using async delegates, for example) to provide asynchronous behavior.
현재 메서드에서 반환 된를에 전달 하 여 IAsyncResult
EndWrite 쓰기가 완료 되 고 리소스가 적절 하 게 해제 되도록 합니다.Pass the IAsyncResult
returned by the current method to EndWrite to ensure that the write completes and frees resources appropriately. EndWrite 모든 호출에 대해를 한 번씩 호출 해야 합니다 BeginWrite .EndWrite must be called once for every call to BeginWrite. 이 작업을 수행 하려면를 호출한 것과 동일한 코드를 사용 하거나에 전달 된 콜백에서이 작업을 수행 하면 BeginWrite
BeginWrite
됩니다.You can do this either by using the same code that called BeginWrite
or in a callback passed to BeginWrite
. 비동기 쓰기를 수행 하는 동안 오류가 발생 하는 경우 EndWrite
이 메서드에서 반환 된를 사용 하 여가 호출 될 때까지 예외가 throw 되지 않습니다 IAsyncResult
.If an error occurs during an asynchronous write, an exception will not be thrown until EndWrite
is called with the IAsyncResult
returned by this method.
스트림을 쓸 수 있는 경우 스트림의 끝에 쓰기는 스트림을 확장 합니다.If a stream is writable, writing at the end of the stream expands the stream.
I/o 작업이 완료 될 때가 아니라 비동기 읽기 또는 쓰기를 실행할 때 스트림의 현재 위치가 업데이트 됩니다.The current position in the stream is updated when you issue the asynchronous read or write, not when the I/O operation completes. 여러 동시 비동기 요청은 요청 완료 순서를 불확실 하 게 렌더링 합니다.Multiple simultaneous asynchronous requests render the request completion order uncertain.
CanWrite현재 인스턴스가 쓰기를 지원 하는지 여부를 확인 하려면 속성을 사용 합니다.Use the CanWrite property to determine whether the current instance supports writing.
스트림이 닫히거나 잘못 된 인수를 전달 하면에서 바로 예외가 throw 됩니다 BeginWrite
.If a stream is closed or you pass an invalid argument, exceptions are thrown immediately from BeginWrite
. 비동기 쓰기 요청 중에 발생 하는 오류 (예: i/o 요청 중의 디스크 오류)는 스레드 풀 스레드에서 발생 하며를 호출할 때 예외를 throw EndWrite
합니다.Errors that occur during an asynchronous write request, such as a disk failure during the I/O request, occur on the thread pool thread and throw exceptions when calling EndWrite
.