Home
Manage Your Code
Snippet: .NET Event Techniques (C#)
Title: .NET Event Techniques Language: C#
Description: .NET Event Techniques Views: 256
Author: Filip K Date Added: 3/24/2008
Copy Code  
1/* !!! check comments in original article re: race conditions */
2/* new way to declare event */
3public event EventHandler Updated = delegate { };   
4  
5protected void UpdatePrice(string tickerSymbol, decimal newPrice, long newVolume)   
6{   
7    _priceList[tickerSymbol] = newPrice;   
8    _volumeList[tickerSymbol] = newVolume;   
9  
10    Updated(this, new MarketFeedEventArgs(tickerSymbol, newPrice, newVolume));   
11}
12
13/* old way to declare event */
14public event EventHandler Updated;   
15  
16protected void UpdatePrice(string tickerSymbol, decimal newPrice, long newVolume)   
17{   
18    _priceList[tickerSymbol] = newPrice;   
19    _volumeList[tickerSymbol] = newVolume;   
20  
21    if(Updated != null)   
22        Updated(this, new MarketFeedEventArgs(tickerSymbol, newPrice, newVolume));   
23} 
Notes
http://devlicio.us/blogs/rob_eisenberg/archive/2008/03/20/net-event-techniques.aspx