<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ryan Vice&#039;s Blog &#187; Delegate</title>
	<atom:link href="http://www.ryanvice.net/tag/delegate/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ryanvice.net</link>
	<description>Implementation notes and development techniques</description>
	<lastBuildDate>Thu, 11 Feb 2010 13:43:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Simplified Event Raising Pattern in C#</title>
		<link>http://www.ryanvice.net/c/simplified-event-raising-pattern-in-c/</link>
		<comments>http://www.ryanvice.net/c/simplified-event-raising-pattern-in-c/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 13:13:49 +0000</pubDate>
		<dc:creator>Ryan Vice</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Delegate]]></category>
		<category><![CDATA[Event]]></category>

		<guid isPermaLink="false">http://www.ryanvice.net/?p=215</guid>
		<description><![CDATA[When creating events most people do something like this

        public event PropertyChangedEventHandler PropertyChanged; 

        internal void RaisePropertyChanged(string propertyName)
        {
            var handler = PropertyChanged;
            if (handler != null)
                handler(this, new PropertyChangedEventArgs(propertyName));
        }
A much simpler approach is to instead do this


        public event PropertyChangedEventHandler PropertyChanged = delegate { };

        internal void [...]]]></description>
			<content:encoded><![CDATA[<p>When creating events most people do something like this</p>
<pre class="brush: csharp;">
        public event PropertyChangedEventHandler PropertyChanged; 

        internal void RaisePropertyChanged(string propertyName)
        {
            var handler = PropertyChanged;
            if (handler != null)
                handler(this, new PropertyChangedEventArgs(propertyName));
        }</pre>
<p>A much simpler approach is to instead do this</p>
<pre class="brush: csharp;">

        public event PropertyChangedEventHandler PropertyChanged = delegate { };

        internal void RaisePropertyChanged(string propertyName)
        {
            // No need for null check because of empty delegate
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }</pre>
<p>which eleminates the need for the null check and eliminates the potential race conditions in multi-threaded code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ryanvice.net/c/simplified-event-raising-pattern-in-c/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
