Is it necessary to flush a Stream
after flushing a StreamWriter
?
public static async Task WriteStringAsync(this Stream stream, string messageString)
{
var encoding = new UTF8Encoding(false); //no BOM
using (var streamWriter = new StreamWriter(stream, encoding))
{
await streamWriter.WriteAsync(messageString);
await streamWriter.FlushAsync();
}
await stream.FlushAsync(); //is this necessary?
}
If your toilet is flushing twice, it is most likely due to the fact that it is staying open too long and flushing too much water. If you have an adjustable flapper, this can be corrected by adjusting your toilet flapper to close quicker.
A dual flush toilet drives lower water usage in your home, thereby saving money on your monthly water bill. The Environmental Protection Agency (EPA) estimates that 4,000 gallons of water can be saved annually in homes that use dual flush toilets.
Since their inception in 1980, dual-flush toilets were made to reduce the amount of water flushed during use. They feature two different buttons to perform two different kinds of flushes. The difference in buttons depends on the waste in the toilet. One button for liquid waste, another for solid waste.
According to the MSDN docs, this could be forgiven as "just making sure"...
StreamWriter.Flush():
Clears all buffers for the current writer and causes any buffered data to be written to the underlying stream.
Stream.Flush():
When overridden in a derived class, clears all buffers for this stream and causes any buffered data to be written to the underlying device.
... However, a closer look at the code in TypeDescriptor shows that StreamWriter.Flush() (and I would assume its asynchronous counterpart FlushAsync) is an overload that calls the primary function, passing two Boolean parameters which instruct the StreamWriter to flush the Stream and the Unicode encoder as well. So, one call to StreamWriter.FlushAsync(), coupled with the await
keyword to ensure the async operation has happened completely, should be fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With