.net - How can I do an atomic write/append in C#, or how do I get files opened with the FILE_APPEND_DATA flag? -


With O_APPEND, the Open () operating system writes OS mostly under Unix and Pozix according to the operating system calling it, which writes I write nuclear and write operations. With this behavior, when you type for local file system, you know that it attaches to the end of the file.

The Windows operating system FILE_APPEND_DATA for Win32 CreateFile () system calls in the appropriate parameters.

Reference:

  http://www.google.com/search?q=msdn+createfile or: http://msdn.microsoft.com/en- Us / library / aa363858 (VS.85) .aspx http://www.google.com/search?q=msdn+IoCreateFileSpecifyDeviceObjectHint Or: http: // www. Google.com/search?q=msdn+IoCreateFileSpecifyDeviceObjectHint  

My problem is, I can not determine how to get this behavior under C # by using Net Framework libraries Is there no way to do this behavior using Net Framework? I do not believe in using FileMode Append gives such behavior in such a way.

Use an overload filestream constructor:

  New filestream (filename, filemod. Open, filesystemrites.appendData, FileShare.Write, 4096, FileOptions.None)  

FileSystemRights.AppendData It is compatible with FILE_APPEND_DATA

The file stream appears to emphasize buffering, so make sure buffer is big enough for each

  Private Zero Button 1_Click (Object Type Receiver, EventArgs E) {write Thread T1 and call  flush ()  = New thread (DoIt); Thread T2 = New thread (DoIt); T1.Start ("A"); T2.Start ("b"); Thread.Sleep (2000); Environment.Exit (0); } Private Zero to DOIT (Object P) {(FileStream FS = New FileStream (Filename, File MOD.Open, FilesystemRights, Approved Data, FileShare, Veerat, 4096, File Option, Non)) {(Streamer Writer Writer = New Streamer (FS) )) {Writer.AutoFlush = true; For (int i = 0; i & lt; 20; ++ i) Writer Wrightite ("{0}: {1: D3} {2: o} hello", p, i, datetime.); }}}  

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -