Hi;
I figured there wasn't an option (I've written file systems and they never
have this). Flush will write the file to disk before returning. Without Flush
the most recent writes to a file can stay in memory forever.
I was hoping for a third approach - the contents will be written to disk
soon, but the call returns immediately.

Signature
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com
Cubicle Wars - http://www.windwardreports.com/film.htm
> Hi Dave,
>
[quoted text clipped - 33 lines]
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no rights.
Ben Voigt - 25 Aug 2006 14:47 GMT
> Hi;
>
[quoted text clipped - 5 lines]
> I was hoping for a third approach - the contents will be written to disk
> soon, but the call returns immediately.
You might be able to do that with an overlapped IOCTL using NtFsControlFile.
But I think that the driver can choose to exhibit synchronous behavior even
for overlapped requests.
>> Hi Dave,
>>
[quoted text clipped - 37 lines]
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
"Peter Huang" [MSFT] - 28 Aug 2006 04:22 GMT
Hi Dave,
Yes, you are correct. We have asynchronous version FileStream related
operation, e.g. BeginRead/BeginWrite. But we did NOT have such a BeginFlush
method.
So to make the Flush method(a synchronous method) to be asynchronous, we
have to do the flush in another thread.
The link I posted has a few method to run certain method on another thread.
Here I post the code snippet using asynchronous Delegate to implement an
asynchronous method call)
class Program
{
public delegate bool FlushDelegate();
public static FileStream fs = null;
public static bool FlushDelegateFunc()
{
Console.WriteLine("Flush ThreadID: " +
Thread.CurrentThread.ManagedThreadId);
fs.Flush();
return true;
}
static void Main(string[] args)
{
fs = new FileStream(@"test.txt", FileMode.OpenOrCreate);
fs.Write(new byte[] { 1, 2 }, 0, 2);
FlushDelegate fDelegate = new FlushDelegate(FlushDelegateFunc);
IAsyncResult ar = fDelegate.BeginInvoke(null, null); //This
call will return immediately.
Console.WriteLine("Main ThreadID: " +
Thread.CurrentThread.ManagedThreadId);
Console.WriteLine("Wait for flush thread return");
fDelegate.EndInvoke(ar);
}
}
NOTE: Because here actually is a multiple threading programming, so we need
to guarantee that the object accessed from the two
threads(Main,FlushDelegateFunc) are thread safe.
From MSDN the public static version of FileStream is thread safe.
If I misunderstood, or you have any other concern, please feel free to let
me know.
Best regards,
Peter Huang
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.