Over a million developers have joined DZone.

Riddle me this: File access & Multi threading

DZone's Guide to

Riddle me this: File access & Multi threading

· ·
Free Resource

RavenDB vs MongoDB: Which is Better? This White Paper compares the two leading NoSQL Document Databases on 9 features to find out which is the best solution for your next project.  

What would be the output of the following code?
var list = new List<Task>();

var fileStream = File.Open("test", FileMode.Create, FileAccess.ReadWrite, FileShare.None);
for (int i = 0; i < 150; i++)
var index = i;
var task = Task.Factory.StartNew(() =>
var buffer = Encoding.ASCII.GetBytes(index + "\r\n");
fileStream.Write(buffer, 0, buffer.Length);


Please note that:

  • What order the data is saved is not important.
  • Preventing data corruption is important.

Can you guess?

Do you pay to use your database? What if your database paid you? Learn more with RavenDB.


Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}