<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Bracketing Operations With IDisposable</title>
	<atom:link href="http://scottbilas.com/blog/bracketing-operations-with-idisposable/feed/" rel="self" type="application/rss+xml" />
	<link>http://scottbilas.com/blog/bracketing-operations-with-idisposable/</link>
	<description>Take what you want, and leave the rest (just like your salad bar).</description>
	<lastBuildDate>Mon, 06 Feb 2012 03:15:56 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Scott</title>
		<link>http://scottbilas.com/blog/bracketing-operations-with-idisposable/#comment-415</link>
		<dc:creator>Scott</dc:creator>
		<pubDate>Wed, 03 Mar 2010 03:34:31 +0000</pubDate>
		<guid isPermaLink="false">http://scottbilas.com/?p=459#comment-415</guid>
		<description>That isn&#039;t quite the same as what this post is about. The closing end of an IDisposable can be chosen by the client to either dispose immediately (via a &#039;using&#039; statement for convenience) or be handed off to another routine as a sort of handle for later closing. This is what allows the chaining, almost by accident. Your example looks like a way of doing arbitrary wrapping of function calls, instead of being forced to rely on a particular language feature that is hard coded on Dispose().

C# doesn&#039;t have support for arbitrary wrapping out of the box, but you can use Castle&#039;s DynamicProxy (http://www.castleproject.org/dynamicproxy/index.html) to slice in similar aspect-oriented programming behaviors. One way we use this at work is to check thread execution permissions for given routines by sticking [AllowedThread(&quot;UI&quot;)] attributes on functions.</description>
		<content:encoded><![CDATA[<p>That isn&#8217;t quite the same as what this post is about. The closing end of an IDisposable can be chosen by the client to either dispose immediately (via a &#8216;using&#8217; statement for convenience) or be handed off to another routine as a sort of handle for later closing. This is what allows the chaining, almost by accident. Your example looks like a way of doing arbitrary wrapping of function calls, instead of being forced to rely on a particular language feature that is hard coded on Dispose().</p>
<p>C# doesn&#8217;t have support for arbitrary wrapping out of the box, but you can use Castle&#8217;s DynamicProxy (<a href="http://www.castleproject.org/dynamicproxy/index.html" rel="nofollow">http://www.castleproject.org/dynamicproxy/index.html</a>) to slice in similar aspect-oriented programming behaviors. One way we use this at work is to check thread execution permissions for given routines by sticking [AllowedThread("UI")] attributes on functions.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: terry</title>
		<link>http://scottbilas.com/blog/bracketing-operations-with-idisposable/#comment-414</link>
		<dc:creator>terry</dc:creator>
		<pubDate>Tue, 02 Mar 2010 17:44:43 +0000</pubDate>
		<guid isPermaLink="false">http://scottbilas.com/?p=459#comment-414</guid>
		<description>or python there are decorators you can use on a function or class method for that sort of thing. It’s quite nice.

for example if you want to bracket a function in a begin/end pair you can write a begin/end decorator for a function:
[code]
def beginEndBracket(func):
    def wrapper(*arg):
        beginX()
        res = func(*arg)
        endX()
        return res
    return wrapper

@being_end_bracket
def somefunctionThatNeedsToBeBracketed():
     drawSomeSnappyDirectXStuff
[/code]
When you call somefunctionThatNeedsToBeBracketed() it does 

Notice the closure.

I mostly use this for timing functions and class methods.</description>
		<content:encoded><![CDATA[<p>or python there are decorators you can use on a function or class method for that sort of thing. It’s quite nice.</p>
<p>for example if you want to bracket a function in a begin/end pair you can write a begin/end decorator for a function:</p>
<pre class="brush: plain;">
def beginEndBracket(func):
    def wrapper(*arg):
        beginX()
        res = func(*arg)
        endX()
        return res
    return wrapper

@being_end_bracket
def somefunctionThatNeedsToBeBracketed():
     drawSomeSnappyDirectXStuff
</pre>
<p>When you call somefunctionThatNeedsToBeBracketed() it does </p>
<p>Notice the closure.</p>
<p>I mostly use this for timing functions and class methods.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott</title>
		<link>http://scottbilas.com/blog/bracketing-operations-with-idisposable/#comment-411</link>
		<dc:creator>Scott</dc:creator>
		<pubDate>Tue, 02 Mar 2010 05:17:46 +0000</pubDate>
		<guid isPermaLink="false">http://scottbilas.com/?p=459#comment-411</guid>
		<description>I decided to write about this a little. See latest post.

http://scottbilas.com/blog/finalizers-an-incomplete-pattern/</description>
		<content:encoded><![CDATA[<p>I decided to write about this a little. See latest post.</p>
<p><a href="http://scottbilas.com/blog/finalizers-an-incomplete-pattern/" rel="nofollow">http://scottbilas.com/blog/finalizers-an-incomplete-pattern/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sander van Rossen</title>
		<link>http://scottbilas.com/blog/bracketing-operations-with-idisposable/#comment-392</link>
		<dc:creator>Sander van Rossen</dc:creator>
		<pubDate>Fri, 12 Feb 2010 08:06:52 +0000</pubDate>
		<guid isPermaLink="false">http://scottbilas.com/?p=459#comment-392</guid>
		<description>Yeah, finalizers are pretty bad.
.NET doesn&#039;t even guarantee that your finalizers are run at all! Which makes them pretty much useless for most purposes.</description>
		<content:encoded><![CDATA[<p>Yeah, finalizers are pretty bad.<br />
.NET doesn&#8217;t even guarantee that your finalizers are run at all! Which makes them pretty much useless for most purposes.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott</title>
		<link>http://scottbilas.com/blog/bracketing-operations-with-idisposable/#comment-390</link>
		<dc:creator>Scott</dc:creator>
		<pubDate>Thu, 11 Feb 2010 21:18:00 +0000</pubDate>
		<guid isPermaLink="false">http://scottbilas.com/?p=459#comment-390</guid>
		<description>Oh good. Whew. :)

As a side note, I really dislike finalizers. I heard that Microsoft has seen the light and is quietly phasing out their usage of them as well.</description>
		<content:encoded><![CDATA[<p>Oh good. Whew. <img src='http://scottbilas.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>As a side note, I really dislike finalizers. I heard that Microsoft has seen the light and is quietly phasing out their usage of them as well.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sander van Rossen</title>
		<link>http://scottbilas.com/blog/bracketing-operations-with-idisposable/#comment-389</link>
		<dc:creator>Sander van Rossen</dc:creator>
		<pubDate>Thu, 11 Feb 2010 21:11:22 +0000</pubDate>
		<guid isPermaLink="false">http://scottbilas.com/?p=459#comment-389</guid>
		<description>My mistake, I must&#039;ve remembered wrong.
I think it&#039;s because all the MSDN examples have virtual dispose(bool) methods, in which case you might have a finalizer somewhere down the inheritance chain, and you&#039;d want to supress your finalizer just in case ;)</description>
		<content:encoded><![CDATA[<p>My mistake, I must&#8217;ve remembered wrong.<br />
I think it&#8217;s because all the MSDN examples have virtual dispose(bool) methods, in which case you might have a finalizer somewhere down the inheritance chain, and you&#8217;d want to supress your finalizer just in case <img src='http://scottbilas.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott</title>
		<link>http://scottbilas.com/blog/bracketing-operations-with-idisposable/#comment-388</link>
		<dc:creator>Scott</dc:creator>
		<pubDate>Thu, 11 Feb 2010 20:04:09 +0000</pubDate>
		<guid isPermaLink="false">http://scottbilas.com/?p=459#comment-388</guid>
		<description>That&#039;s news to me.. Are you sure? Where did you find out about that, do you have a link?

I just looked at an IDisposable class in Reflector, and there&#039;s nothing finalizer-related in there. Unless you mean that the CLR is doing something deep inside, which sounds unlikely to me.</description>
		<content:encoded><![CDATA[<p>That&#8217;s news to me.. Are you sure? Where did you find out about that, do you have a link?</p>
<p>I just looked at an IDisposable class in Reflector, and there&#8217;s nothing finalizer-related in there. Unless you mean that the CLR is doing something deep inside, which sounds unlikely to me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sander van Rossen</title>
		<link>http://scottbilas.com/blog/bracketing-operations-with-idisposable/#comment-387</link>
		<dc:creator>Sander van Rossen</dc:creator>
		<pubDate>Thu, 11 Feb 2010 19:57:23 +0000</pubDate>
		<guid isPermaLink="false">http://scottbilas.com/?p=459#comment-387</guid>
		<description>If you inherit from IDispose, a finalizer is implicitly added behind the scenes</description>
		<content:encoded><![CDATA[<p>If you inherit from IDispose, a finalizer is implicitly added behind the scenes</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott</title>
		<link>http://scottbilas.com/blog/bracketing-operations-with-idisposable/#comment-386</link>
		<dc:creator>Scott</dc:creator>
		<pubDate>Thu, 11 Feb 2010 16:48:00 +0000</pubDate>
		<guid isPermaLink="false">http://scottbilas.com/?p=459#comment-386</guid>
		<description>Why would you SuppressFinalize on a class without a finalizer?

Regarding which gc it ends up in - it again goes back to the relative costs of the disposer from whatever operations it is bracketing.</description>
		<content:encoded><![CDATA[<p>Why would you SuppressFinalize on a class without a finalizer?</p>
<p>Regarding which gc it ends up in &#8211; it again goes back to the relative costs of the disposer from whatever operations it is bracketing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sander van Rossen</title>
		<link>http://scottbilas.com/blog/bracketing-operations-with-idisposable/#comment-385</link>
		<dc:creator>Sander van Rossen</dc:creator>
		<pubDate>Thu, 11 Feb 2010 08:17:29 +0000</pubDate>
		<guid isPermaLink="false">http://scottbilas.com/?p=459#comment-385</guid>
		<description>Well at the least I would call GC.SupressFinalize at the end of your Dispose method to avoid the object from being finalized, which is (relatively) expensive.

I&#039;m not entirely sure if it&#039;ll prevent the object from being promoted to the next GC generation though, it still might.</description>
		<content:encoded><![CDATA[<p>Well at the least I would call GC.SupressFinalize at the end of your Dispose method to avoid the object from being finalized, which is (relatively) expensive.</p>
<p>I&#8217;m not entirely sure if it&#8217;ll prevent the object from being promoted to the next GC generation though, it still might.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

