Fix WriteFile flushing stream more than once

WriteFile creates an Action which disposes of the stream, this is then
sent to WriteFileCommon which invokes this action and attempts to flush
the stream a second time.  This can raise an ObjectDisposed Exception as
Flush will be called on a closed stream.