Appending to a file passing a reference to the writer

Hello,

I would like to be able to open up a file stream from a high level function and then append down at a low level which is timing critical. I fell that declaring and opening a file stream multiple times a second may impact performance. Is there a clean way to do this?

Thanks


bartdspAsked:
Who is Participating?
 
CodeCruiserCommented:
Is it within a same class? You can use a class level variable for holding the reference to streamwriter and then use it across functions.
0
 
Miguel OzSoftware EngineerCommented:
You can use viewstate,check:
http://msdn.microsoft.com/en-us/library/aa287536(v=vs.71).aspx
e.g
ViewState["MyValue"] = "1";
0
 
Miguel OzSoftware EngineerCommented:
Please disregard my previous post. Wrong answer to your question.
CodeCruiser comment is the way to go if you do not have memory constraints and your program is the only user of the file.
If you are doing logging, you are better off using solutions like log4net:
http://logging.apache.org/log4net/
0
 
bartdspAuthor Commented:
Thanks! Sorry to be slow in responding.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.