FileStream.EndWrite(IAsyncResult) Yöntem

Tanım

Zaman uyumsuz yazma işlemini sonlandırır ve G/Ç işlemi tamamlanana kadar engeller. (Bunun yerine kullanmayı WriteAsync(Byte[], Int32, Int32, CancellationToken) göz önünde bulundurun.)

public:
 override void EndWrite(IAsyncResult ^ asyncResult);
public override void EndWrite (IAsyncResult asyncResult);
override this.EndWrite : IAsyncResult -> unit
Public Overrides Sub EndWrite (asyncResult As IAsyncResult)

Parametreler

asyncResult
IAsyncResult

Bekleyen zaman uyumsuz G/Ç isteği.

Özel durumlar

asyncResult, null değeridir.

Bu IAsyncResult nesne, bu sınıfta çağrılarak BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object) oluşturulmadı.

EndWrite(IAsyncResult) birden çok kez çağrılır.

Akış kapatıldı veya bir iç hata oluştu.

Örnekler

Bu kod örneği, oluşturucu için FileStream(String, FileMode, FileAccess, FileShare, Int32, Boolean) sağlanan daha büyük bir örneğin parçasıdır.

   static void EndWriteCallback( IAsyncResult^ asyncResult )
   {
      State^ tempState = dynamic_cast<State^>(asyncResult->AsyncState);
      FileStream^ fStream = tempState->FStream;
      fStream->EndWrite( asyncResult );
      
      // Asynchronously read back the written data.
      fStream->Position = 0;
      asyncResult = fStream->BeginRead( tempState->ReadArray, 0, tempState->ReadArray->Length, gcnew AsyncCallback( &FStream::EndReadCallback ), tempState );
      
      // Concurrently do other work, such as 
      // logging the write operation.
   }

};
static void EndWriteCallback(IAsyncResult asyncResult)
{
    State tempState = (State)asyncResult.AsyncState;
    FileStream fStream = tempState.FStream;
    fStream.EndWrite(asyncResult);

    // Asynchronously read back the written data.
    fStream.Position = 0;
    asyncResult = fStream.BeginRead(
        tempState.ReadArray, 0 , tempState.ReadArray.Length,
        new AsyncCallback(EndReadCallback), tempState);

    // Concurrently do other work, such as
    // logging the write operation.
}
let endWriteCallback (asyncResult: IAsyncResult) =
    let tempState = asyncResult.AsyncState :?> State
    let fStream = tempState.FStream
    fStream.EndWrite asyncResult

    // Asynchronously read back the written data.
    fStream.Position <- 0

    let asyncResult =
        fStream.BeginRead(tempState.ReadArray, 0, tempState.ReadArray.Length, AsyncCallback endReadCallback, tempState)

    // Concurrently do other work, such as
    // logging the write operation.
    ()
Private Shared Sub EndWriteCallback(asyncResult As IAsyncResult)
    Dim tempState As State = _
        DirectCast(asyncResult.AsyncState, State)
    Dim fStream As FileStream = tempState.FStream
    fStream.EndWrite(asyncResult)

    ' Asynchronously read back the written data.
    fStream.Position = 0
    asyncResult = fStream.BeginRead( _ 
        tempState.ReadArray, 0 , tempState.ReadArray.Length, _
        AddressOf EndReadCallback, tempState)

    ' Concurrently do other work, such as 
    ' logging the write operation.
End Sub

Açıklamalar

.NET Framework 4 ve önceki sürümlerde, zaman uyumsuz dosya işlemleri uygulamak için ve EndWrite gibi BeginWrite yöntemleri kullanmanız gerekir. Bu yöntemler, eski kodu desteklemek için .NET Framework 4.5'te hala kullanılabilir; ancak , WriteAsync, CopyToAsyncve FlushAsyncgibi ReadAsyncyeni zaman uyumsuz yöntemler zaman uyumsuz dosya işlemlerini daha kolay uygulamanıza yardımcı olur.

Bu yöntem geçersiz kılar EndWrite.

EndWrite , üzerindeki her IAsyncResultBeginWriteüzerinde tam olarak bir kez çağrılmalıdır. EndWrite G/Ç işlemi tamamlanana kadar engeller.

Şunlara uygulanır

Ayrıca bkz.