System.IO.FileStream.FlushAsync C# (CSharp) Method

FlushAsync() public method

public FlushAsync ( CancellationToken cancellationToken ) : Task
cancellationToken CancellationToken
return Task
        public override Task FlushAsync(CancellationToken cancellationToken)
        {
            // If we have been inherited into a subclass, the following implementation could be incorrect
            // since it does not call through to Flush() which a subclass might have overridden.  To be safe 
            // we will only use this implementation in cases where we know it is safe to do so,
            // and delegate to our base class (which will call into Flush) when we are not sure.
            if (GetType() != typeof(FileStream))
                return base.FlushAsync(cancellationToken);

            return FlushAsyncInternal(cancellationToken);
        }

Usage Example

 public async Task SaveFile(string name, Stream stream)
 {
     var fullPath = GetFullPath(name);
     using (var fs = new FileStream(fullPath, FileMode.OpenOrCreate, FileAccess.Write))
     {
         await stream.CopyToAsync(fs).ConfigureAwait(false);
         await stream.FlushAsync().ConfigureAwait(false);
         await fs.FlushAsync().ConfigureAwait(false);
     }
 }
All Usage Examples Of System.IO.FileStream::FlushAsync