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

FlushAsync() public method

public FlushAsync ( ) : System.Threading.Tasks.Task
return System.Threading.Tasks.Task
        public override Task FlushAsync()
        {
            // 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(StreamWriter))
            {
                return base.FlushAsync();
            }

            // flushEncoder should be true at the end of the file and if
            // the user explicitly calls Flush (though not if AutoFlush is true).
            // This is required to flush any dangling characters from our UTF-7 
            // and UTF-8 encoders.  
            if (_stream == null)
            {
                throw new ObjectDisposedException(null, SR.ObjectDisposed_WriterClosed);
            }

            CheckAsyncTaskInProgress();

            Task task = FlushAsyncInternal(true, true, _charBuffer, _charPos);
            _asyncWriteTask = task;

            return task;
        }

Usage Example

 public override async Task WriteToStreamAsync(Type type, object value, Stream stream, HttpContent content, TransportContext transportContext)
 {
     using (stream)
     {
         Encoding encoding = SelectCharacterEncoding(content.Headers);
         using (var writer = new StreamWriter(stream, encoding))
         {
             var individuals = value as IEnumerable<Individual>;
             if (individuals != null)
             {
                 foreach (var individu in individuals)
                 {
                     await writer.WriteLineAsync(String.Format("{0,-10};{1,-10};{2,-10}", individu.Id, individu.FirstName, individu.LastName));
                 }
                 await writer.FlushAsync();
             }
             var individual = value as Individual;
             if (individual != null)
             {
                 await writer.WriteLineAsync(String.Format("{0,-10};{1,-10};{2,-10}", individual.Id, individual.FirstName, individual.LastName));
                 await writer.FlushAsync();
             }
         }
     }
 }
All Usage Examples Of System.IO.StreamWriter::FlushAsync