C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




delegate's null test


Posted Date: 03 Jun 2008    Resource Type: Tips    Category: Windows
Author: Debasmit SamalMember Level: Gold    
Rating: Points: 2



Really it is a Qustion not a topic.

Q .should we have a null test before invoking a delegate?

A: suppose we have an event in a class, we need to add a null test before you call the delegate. Typically, we would write:

if (Click != null)
Click(arg1, arg2);

There is actually a possible condition - the event can be cleared between the first and second line.
we would actually want to write:

ClickHandler handler = Click;

if (handler != null)
handler(arg1, arg2);
usually. we might want to do some other sort of synchronization in other scenarios.

So back to the main question. Why is the null test required?

We can't change the existing behavior of calling through a delegate as some apps may depend on it, so it would have to be an addition to the language.

We have talked about adding an Invoke() keyword to the language to make this easier, but after a fair bit of discussion, we decided that we couldn't do the right thing all the time, so we elected not to do anything.




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: A Compact Executable Briefcase Wallpaper
Previous Resource: Forgot to mention subject in mail???
Return to Discussion Resource Index
Post New Resource
Category: Windows


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use