NetworkComms Network Program Development Notes (1): A secure trigger event in a multi-threaded environment. jquery triggers the click event.

Source: Internet
Author: User

NetworkComms Network Program Development Notes (1): A secure trigger event in a multi-threaded environment. jquery triggers the click event.

Triggering an event in multiple threads may throw an exception with the reference being null. This issue is discussed on the Internet many times.

The NetworkComms communication framework has almost no use events, so this issue does not exist in the core communication framework.

I checked a lot of information online, such as the following:

 

Our solution:

 public static class Extensions    {        public static void Raise<T>(this EventHandler<T> handler, object sender, T args) where T : EventArgs        {            if (handler != null)                handler(sender, args);        }    }

The event definition is as follows:

// Public class FileEventArgs: EventArgs {public FileEventArgs (FileDetail fileInfo) {FileInfo = fileInfo;} public FileDetail FileInfo {get; set ;}}
 public event EventHandler<FileEventArgs> NewDoubleClick;

Trigger event statement:

 NewDoubleClick.Raise(this,new FileEventArgs(this.FileInfo));

 

 

References

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

Related Article

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.