NETWORKCOMMS Network Program Development Note (i): A secure triggering event in a multithreaded environment

Source: Internet
Author: User

Triggering an event in a multi-thread may throw an exception with a null reference, a problem that is discussed online.

The NETWORKCOMMS communication framework itself has little use of events, so there is no such problem in the core communication framework.

On the internet to check a lot of information, such as the following:

The solution we use:

 Public Static class Extensions    {        publicstaticvoid raise<t> (Thisobjectwhere  T:eventargs        {            ifnull)                handler (sender, args);        }    } 

Define the event as follows:

// event Arguments    that contain file information  Public class Fileeventargs:eventargs    {        public  Fileeventargs (filedetail  fileInfo)        {            = fileInfo;        }          publicgetset;}    }
 Public Event Eventhandler<fileeventargs> Newdoubleclick;

Trigger Event Statement:

Newdoubleclick.raise (This,new Fileeventargs. FileInfo));

Reference articles

Http://stackoverflow.com/questions/786383/c-sharp-events-and-thread-safety
Http://stackoverflow.com/questions/840715/the-proper-way-of-raising-events-in-the-net-framework
http://stackoverflow.com/questions/9033/hidden-features-of-c/9282#9282
Http://stackoverflow.com/questions/840715/the-proper-way-of-raising-events-in-the-net-framework
Http://stackoverflow.com/questions/231525/raising-c-sharp-events-with-an-extension-method-is-it-bad
Http://blogs.msdn.com/b/ericlippert/archive/2009/04/29/events-and-races.aspx
Http://stackoverflow.com/questions/786383/c-sharp-events-and-thread-safety
http://codeblog.jonskeet.uk/2015/01/30/clean-event-handlers-invocation-with-c-6/
http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/3796170- Add-raise-extension-method-for-eventhandler-and

Www.cnblogs.com/networkcomms

www.networkcomms.cn

NETWORKCOMMS Network Program Development Note (i): A secure triggering event in a multithreaded environment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.