multithreading - C#: Thread-safe events -


What is the implementation under thread-safe? If not, then what am I missing? Do I need a unstable keyword anywhere? Or a lock somewhere in the OnProcessingCompleted method? If so, then where?

  Public abstract class process: IPCCs {Private Readonly Object Full EventLock = new object (); Private Event EventHandler & lt; Process Liquid Avent ARG & gt; ProcessCompleted; Event event handler & lt; Process end events arrow & gt; IProcess.Process Complete {add {lock (Full EventLock) process complete = value; } {Remove (Full EventLock) Process - = Value; }} Secure Fare OnProcessingCompleted (ProcessCompletedEventArgs E) {EventHandler & lt; ProcessCompletedEventArgs & gt; Handler = complete process; If (handler! = Null) handler (this, e); Note:  I have a private event and clear interface stuff because it is an abstract base class. And the classes which are received from it, should not do anything directly with that incident. Class cover was added so that it is more clear) =)    

there is no need Private process completed to be a event - it can be just a field: private event handler < Process involves event event & gt; Process completed; - Within the classroom, he always goes straight to the ground, so the event stuff is lost anyway.

From the perspective of which object you have shown with clear lock, more than having an object field-like event (i.e. public event event handler & lt; ProcessCompletedEventArgs & gt; process completed; ) < Em> too is not too thread-safe - the only difference is that you do not lock it "(which is a good thing - you ideal this Avoid locking on.) "Handler variable" approach is correct, but still.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -