lib/Task-Parallel-Library/StreamExtensions.cs
/// <summary>
/// Asynchronously clears all buffers for a stream and causes any buffered data to be written to the underlying device,
/// and monitors cancellation requests.
/// </summary>
/// <remarks>
/// <para>If the operation is canceled before it completes, the returned task contains the <see cref="TaskStatus.Canceled"/>
/// value for the <see cref="Task.Status"/> property.</para>
/// <para>
/// If a derived class does not flush the buffer in its implementation of the <see cref="Stream.Flush()"/> method,
/// the <see cref="FlushAsync(Stream)"/> method will not flush the buffer.
/// </para>
/// </remarks>
/// <param name="stream">The stream to flush.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests. The default value is <see cref="CancellationToken.None"/>.</param>
/// <returns>A task that represents the asynchronous flush operation.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="stream"/> is <see langword="null"/>.</exception>
/// <exception cref="ObjectDisposedException">If <paramref name="stream"/> has been disposed.</exception>
Asynchronously clears all buffers for a stream and causes any buffered data to be written to the underlying device,
and monitors cancellation requests.
Asynchronously clears all buffers for a stream and causes any buffered data to be written to the underlying device and monitors cancellation requests .
public static Task FlushAsync(this Stream stream, CancellationToken cancellationToken)
        {
            if (stream == null)
                throw new ArgumentNullException("stream");
            if (cancellationToken.IsCancellationRequested)
                return GetCanceledTask<bool>();
            #if NET45PLUS
            return stream.FlushAsync(cancellationToken);
            #else
            return Task.Factory.StartNew(state => ((Stream)state).Flush(), stream, cancellationToken, TaskCreationOptions.None, TaskScheduler.Default);
            #endif
        }
public static Task FlushAsync ( this Stream stream , CancellationToken cancellationToken ) { if ( stream == null ) throw new ArgumentNullException ( " " ) ; if ( cancellationToken . IsCancellationRequested ) return GetCanceledTask < bool > ( ) ; if NET45PLUS return stream . FlushAsync ( cancellationToken ) ; else return Task . Factory . StartNew ( state => ( ( Stream ) state ) . Flush ( ) , stream , cancellationToken , TaskCreationOptions . None , TaskScheduler . Default ) ; endif }
Asynchronously clears all buffers for a stream and causes any buffered data to be written to the underlying device,
and monitors cancellation requests.
Asynchronously clears all buffers for a stream and causes any buffered data to be written to the underlying device and monitors cancellation requests .
// This code requires the `Stream` class provide an implementation of `FlushAsync`. The unit tests will // detect any case where this results in a stack overflow.
A task that represents the asynchronous flush operation.
A task that represents the asynchronous flush operation .
If  is .
If is .
If  has been disposed.
If has been disposed .
Stream
this
cancellationToken
CancellationToken
The token to monitor for cancellation requests. The default value is .
The token to monitor for cancellation requests . The default value is .
stream
The stream to flush.
The stream to flush .
remarks
If the operation is canceled before it completes, the returned task contains the
value for the  property.
If a derived class does not flush the buffer in its implementation of the  method,
the  method will not flush the buffer.
If the operation is canceled before it completes the returned task contains the value for the property . If a derived class does not flush the buffer in its implementation of the method the method will not flush the buffer .