<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: C# Delegate Shortcut &#8211; No more null testing on events for subscribers</title>
	<atom:link href="http://team.pushbomb.com/2008/11/27/very_nice_c_sharp_shortcut/feed/" rel="self" type="application/rss+xml" />
	<link>http://team.pushbomb.com/2008/11/27/very_nice_c_sharp_shortcut/</link>
	<description>tv programmed by the collective</description>
	<lastBuildDate>Mon, 08 Mar 2010 23:37:38 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Anonymous</title>
		<link>http://team.pushbomb.com/2008/11/27/very_nice_c_sharp_shortcut/#comment-625</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Mon, 20 Jul 2009 15:27:04 +0000</pubDate>
		<guid isPermaLink="false">http://dcarr.wordpress.com/2008/11/27/very_nice_c_sharp_shortcut/#comment-625</guid>
		<description>This is especially nice as I see sometimes people have special logic &#039;if the event handler is not null&#039;

This is bad. The observer pattern (which is what events are) is about never having to care if you have 0, 1 or more subscribers. If you hace logic that cares, it is broken almost certainly.....



Why? Because &#039;you will never know&#039; in a real framework environment if/how many/etc. about who is listening at any given moment to your events. You always have to assume there could be nobody.

One interest caveat: Do you have unrecoverable cases where you simply cannot continue if there are no subscribers to any given event? 



For this case it is dangerous ground. I would encourage a rethink of the design. For example, (and this happens far too often in Silverlight due to the async nature of it) I have a few background activities which are retrieving the initialization data for my app. I have no idea when this will all be done exactly so I have a method of raising an event when &#039;the bare minimum&#039; is done. 

I AM the one subscribing to the framework events (the WebClient download string/stream callbacks for example) not my &#039;client&#039; who is waiting on the result.

So I expost an event called &#039;InitializationComplete&#039;. I introduced a regression and it is not subscribed. 

So I sink MY events and get the result. The data is there and I raise my event (blissfully not knowing if anyone is on the other end).

So what happens?????


In my opinion there would need (in any case) to be a reasonable timeout defined. This is on &#039;my client&#039;s&#039; code. So when it is done with all it needs to do and is basically now waiting for this event, it should not be forever. 

In this case it will timeout. HOWEVER, it is easier to debug and you immediately know the issue if that null check is performed..

Hmm.... I guess this is one for &#039;personal preference&#039;? Thoughts?

Damon</description>
		<content:encoded><![CDATA[<p>This is especially nice as I see sometimes people have special logic &#8216;if the event handler is not null&#8217;</p>
<p>This is bad. The observer pattern (which is what events are) is about never having to care if you have 0, 1 or more subscribers. If you hace logic that cares, it is broken almost certainly&#8230;..</p>
<p>Why? Because &#8216;you will never know&#8217; in a real framework environment if/how many/etc. about who is listening at any given moment to your events. You always have to assume there could be nobody.</p>
<p>One interest caveat: Do you have unrecoverable cases where you simply cannot continue if there are no subscribers to any given event? </p>
<p>For this case it is dangerous ground. I would encourage a rethink of the design. For example, (and this happens far too often in Silverlight due to the async nature of it) I have a few background activities which are retrieving the initialization data for my app. I have no idea when this will all be done exactly so I have a method of raising an event when &#8216;the bare minimum&#8217; is done. </p>
<p>I AM the one subscribing to the framework events (the WebClient download string/stream callbacks for example) not my &#8216;client&#8217; who is waiting on the result.</p>
<p>So I expost an event called &#8216;InitializationComplete&#8217;. I introduced a regression and it is not subscribed. </p>
<p>So I sink MY events and get the result. The data is there and I raise my event (blissfully not knowing if anyone is on the other end).</p>
<p>So what happens?????</p>
<p>In my opinion there would need (in any case) to be a reasonable timeout defined. This is on &#8216;my client&#8217;s&#8217; code. So when it is done with all it needs to do and is basically now waiting for this event, it should not be forever. </p>
<p>In this case it will timeout. HOWEVER, it is easier to debug and you immediately know the issue if that null check is performed..</p>
<p>Hmm&#8230;. I guess this is one for &#8216;personal preference&#8217;? Thoughts?</p>
<p>Damon</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yoann. B</title>
		<link>http://team.pushbomb.com/2008/11/27/very_nice_c_sharp_shortcut/#comment-447</link>
		<dc:creator>Yoann. B</dc:creator>
		<pubDate>Fri, 28 Nov 2008 17:08:51 +0000</pubDate>
		<guid isPermaLink="false">http://dcarr.wordpress.com/2008/11/27/very_nice_c_sharp_shortcut/#comment-447</guid>
		<description>Nice tips!

Thanks !</description>
		<content:encoded><![CDATA[<p>Nice tips!</p>
<p>Thanks !</p>
]]></content:encoded>
	</item>
</channel>
</rss>
