Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8865191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:26:31+00:00 2026-06-14T16:26:31+00:00

Given this example code: 1: using (StreamWriter sw = new StreamWriter(@C:\file.txt)) 2: { 3:

  • 0

Given this example code:

1:   using (StreamWriter sw = new StreamWriter(@"C:\file.txt"))
2:   {
3:       sw.WriteLine(great_string);
4:   }
5:
6:   using (StreamReader sr = new StreamReader(@"C:\file.txt"))
7:   {
8:       sr.ReadToEnd();
9:   }

Is it possible that the great_string written on line 3 would not be present in C:\file.txt when StreamReader.ReadToEnd is called on line 8? It seems to me that it would be possible, because your average CPU works much faster than your average HDD, but I’ve been testing this today, and so far the string written on line 3 is always present when I read the file on line 8. I’m thinking that maybe the using statement won’t close the stream until all of the data is written to / read from the file, thus preventing the kind of situation that I’m asking about.

I’ve been reading about the StreamWriter.Close method on MSDN, and it states the following:

You must call Close to ensure that all data is correctly written out to the underlying stream.

But it doesn’t say WHEN the data will be written out to the underlying stream.

Thanks in advance for any info on this subject. I did search for answers to this question, but I didn’t find anything…I didn’t really know what terms to search for.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T16:26:32+00:00Added an answer on June 14, 2026 at 4:26 pm

    The data might not be physically present on the HDD after calling Close but the system (the windows Kernel) will give the appearance that it is. And all that matters is the appearance.

    If you read from the file just written Windows will either ask the HDD or serve from cache.

    If this was not the case it would be hard to write reliable programs because the order of effects could change arbitrarily across functions and even processes. It would be chaos. So the system guarantees sequential consistency.

    If you think about it: If this serialization property was not present a file could have multiple contents at the same time! Read it the first time and you see the old contents. Read it again and you suddenly see changes appear. This kind of behavior is not possible, fortunately.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using code::blocks, with, I believe gcc. Given the example code (this is
Given this code: using (var conn = new SqlConnection(...)) { conn.Open(); using (var cmd
Given this example XML file: <doc> <tag> Hello ! </tag> <tag> My name is
I am using this example to display images, stored in my File-Stream Enabled database
I use this code to encrypt a string (basically, this is the example given
I'm currently writing very explicit selectors in my jQuery code. For example given this
I need some explanation for this code. This is the example code given by
I know how to do this... I'll give example code below. But I can't
Given this example data set: ----------------------------- | item | date | val | -----------------------------
Given this example, how would I return the result of the equation rather than

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.