RSS 2.0

Personal Info:

Joe Send mail to the author(s) is a lead architect on an OS incubation project at Microsoft, and was the architect for Parallel Extensions to .NET. He is an author and frequent speaker.

Disclaimer:
The content of this site are my own personal opinions and do not represent my employer's view in anyway.

© 2010, Joe Duffy

 
 Friday, December 10, 2004

So you may or may not have noticed that System.IO.Stream both has a Close() method and implements IDisposable, meaning it has a Dispose() method, too. (Note: it's explicitly implemented, meaning that to access it you'll need to use an IDisposable typed reference in C#, e.g. as in ((IDisposable)myStream).Dispose().) Stream is an abstract base class, the most common derivitive being FileStream.

Without consulting Reflector, ;) can you answer these questions?

  • What does invoking Close() on an open Stream do?
  • What does invoking Dispose() on an open Stream do?
  • Should you call both at some point in a Stream's lifecycle?
    • If so, when and in what order?
    • If not, why?
  • Can you call only one without having to call the other?
  • Is it weird that there is both a Close() and Dispose() on a single type, or does that seem natural? Based on your understanding of the pattern, do you think we should continue to use it, or is there a better one?

I have a much lengthier post that I'm writing up regarding an internal design debate we're currently involved in - responses will help to shape both the post and the debate. :)

12/10/2004 10:04:53 PM (Pacific Standard Time, UTC-08:00)  #    Comments [53]
Tracked by:
http://www.bluebytesoftware.com/blog/PermaLink.aspx?guid=1fe0f820-5b2b-4b17-82af... [Pingback]

 

Recent Entries:

Search:

Browse by Date:
<September 2010>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

Browse by Category:

Notables: