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