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