<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>StreamWriter Buffered Data Lost MDA (or a cute finalizer trick) [Brian Grunkemeyer]</title><link>http://blogs.msdn.com/bclteam/archive/2004/08/13/214405.aspx</link><description>A somewhat common problem when getting started with developing managed code and using our IO package is forgetting to close a Stream or a StreamWriter. Users who write code like this will be disappointed: void Foo() { StreamWriter sw = new StreamWriter("file.txt");</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: StreamWriter Buffered Data Lost MDA (or a cute finalizer trick) [Brian Grunkemeyer]</title><link>http://blogs.msdn.com/bclteam/archive/2004/08/13/214405.aspx#214492</link><pubDate>Sat, 14 Aug 2004 05:52:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:214492</guid><dc:creator>Aaron</dc:creator><description>I was talking to someone not too long ago who was experiencing a similar problem with DataReaders.&lt;br&gt;&lt;br&gt;People weren't closing them, eventually causing him to run out of connections. Seems like this would fix that as well.&lt;br&gt;&lt;br&gt;Rad.</description></item><item><title>re: StreamWriter Buffered Data Lost MDA (or a cute finalizer trick) [Brian Grunkemeyer]</title><link>http://blogs.msdn.com/bclteam/archive/2004/08/13/214405.aspx#214512</link><pubDate>Sat, 14 Aug 2004 07:53:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:214512</guid><dc:creator>AlexLev</dc:creator><description>You also should mention that other nice effect appear if you construct StreamWriter on top of Stream.&lt;br&gt;I.e.&lt;br&gt;Stream stream = new FileStream(&amp;quot;foo.txt&amp;quot;);&lt;br&gt;using (StreamWriter writer = new StreamWriter(stream))&lt;br&gt;{writer.WriteLine(&amp;quot;Line1&amp;quot;);}&lt;br&gt;&lt;br&gt;using (StreamWriter writer = new StreamWriter(stream))&lt;br&gt;{writer.WriteLine(&amp;quot;Line2&amp;quot;);}&lt;br&gt;&lt;br&gt;So writer closes stream immediately after writing &amp;quot;Line1&amp;quot; and then second writer just throws &amp;quot;already closed&amp;quot; exception.&lt;br&gt;Looking through MSDN there is even sample with exactly this code that definitely can't run :)&lt;br&gt;</description></item><item><title>Grunk on finalizers and StreamWriter</title><link>http://blogs.msdn.com/bclteam/archive/2004/08/13/214405.aspx#214522</link><pubDate>Sat, 14 Aug 2004 08:56:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:214522</guid><dc:creator>Brad Abrams </dc:creator><description /></item><item><title>re: StreamWriter Buffered Data Lost MDA (or a cute finalizer trick) [Brian Grunkemeyer]</title><link>http://blogs.msdn.com/bclteam/archive/2004/08/13/214405.aspx#214628</link><pubDate>Sat, 14 Aug 2004 20:44:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:214628</guid><dc:creator>James Manning</dc:creator><description>The manual expansion of using had sw.Close() in the finally, but I'd imagine that it's sw.Dispose() instead (which will of course will eventually do the same thing).&lt;br&gt;&lt;br&gt;Not that it much matters, just pointing out in case anyone's confused by it. :)</description></item><item><title>re: StreamWriter Buffered Data Lost MDA (or a cute finalizer trick) [Brian Grunkemeyer]</title><link>http://blogs.msdn.com/bclteam/archive/2004/08/13/214405.aspx#215340</link><pubDate>Tue, 17 Aug 2004 00:04:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:215340</guid><dc:creator>Brian Grunkemeyer</dc:creator><description>James, yes, you're right in that Dispose and Close are equivalent.  The problem is that you can't call Dispose on the StreamWriter without casting it to IDisposable.  When we added in the IDisposable interface in V1, we felt Close made more sense on all IO-related classes, so in some cases (like TextWriter), we privately implemented the IDisposable interface.  In retrospect this may have been a mistake - either both should have been public, or we should have simply renamed Close to Dispose.&lt;br&gt;&lt;br&gt;Alex, if you happen to see that buggy code in MSDN, feel free to click on the &amp;quot;Send feedback&amp;quot; link at the bottom of the page to let us know about it.  If the docs &amp;amp; samples can be improved and you know exactly how or at least why, sending in feedback is a great idea.  That feedback does go to the correct person in our user education group, and you'll usually see the improvement in the next one or two quarterly MSDN releases.</description></item><item><title>re: StreamWriter Buffered Data Lost MDA (or a cute finalizer trick) [Brian Grunkemeyer]</title><link>http://blogs.msdn.com/bclteam/archive/2004/08/13/214405.aspx#215469</link><pubDate>Tue, 17 Aug 2004 05:22:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:215469</guid><dc:creator>Scott Willeke</dc:creator><description>Can third party components implement managed debugging assistants?</description></item><item><title>re: StreamWriter Buffered Data Lost MDA (or a cute finalizer trick) [Brian Grunkemeyer]</title><link>http://blogs.msdn.com/bclteam/archive/2004/08/13/214405.aspx#216857</link><pubDate>Thu, 19 Aug 2004 03:21:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:216857</guid><dc:creator>Brian Grunkemeyer</dc:creator><description>Unfortunately, 3rd parties won't be able to add MDA's in Whidbey.  Some people are looking at doing that work in our Orcas release, after Whidbey.</description></item><item><title>Blog link of the week 33</title><link>http://blogs.msdn.com/bclteam/archive/2004/08/13/214405.aspx#220389</link><pubDate>Wed, 25 Aug 2004 21:29:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:220389</guid><dc:creator>Daniel Moth</dc:creator><description>&lt;a target="_new" href="http://www.zen13120.zen.co.uk/Blog/2004/08/blog-link-of-week-33-as-in-week-ending.html"&gt;http://www.zen13120.zen.co.uk/Blog/2004/08/blog-link-of-week-33-as-in-week-ending.html&lt;/a&gt;</description></item><item><title>More cool stuff in Whidbey</title><link>http://blogs.msdn.com/bclteam/archive/2004/08/13/214405.aspx#241675</link><pubDate>Wed, 13 Oct 2004 15:31:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:241675</guid><dc:creator>Girish Bharadwaj</dc:creator><description /></item></channel></rss>