.NET & Funky Fresh

Syndication

News

  • <script type="text/javascript" src="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&amp;MarketPlace=US&amp;ID=V20070822/US/bluspiconinc-20/8001/8b68bf4b-6724-40e7-99a5-a6decf6d8648"> </script>
Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
.NET Event Techniques

Yesterday I was reviewing some code created by the Prism team.  I came across a rather clever event implementation that I hadn't see before:

public event EventHandler Updated = delegate { };

protected void UpdatePrice(string tickerSymbol, decimal newPrice, long newVolume)
{
	_priceList[tickerSymbol] = newPrice;
	_volumeList[tickerSymbol] = newVolume;

	Updated(this, new MarketFeedEventArgs(tickerSymbol, newPrice, newVolume));
}

Normally I would write this code like so:

public event EventHandler Updated;

protected void UpdatePrice(string tickerSymbol, decimal newPrice, long newVolume)
{
	_priceList[tickerSymbol] = newPrice;
	_volumeList[tickerSymbol] = newVolume;

	if(Updated != null)
		Updated(this, new MarketFeedEventArgs(tickerSymbol, newPrice, newVolume));
}

I commented that this wasn't the way I was used to seeing events declared or fired and that I thought it might confuse some people.  Ayende informed me that this is the way he normally does things, stating that it was threadsafe and no fuss.  I'm thinking about adopting this technique and was wondering if I'm the only one who hasn't seen this before now.  Also, does anyone have any opinions one way or the other about this particular implementation?


Posted 03-20-2008 12:17 PM by Rob Eisenberg

[Advertisement]

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)