Events in D
bitwise via Digitalmars-d
digitalmars-d at puremagic.com
Tue Aug 29 10:27:50 PDT 2017
On Tuesday, 29 August 2017 at 05:10:25 UTC, bitwise wrote:
> [...]
I think I should clarify for anyone with limited C# experience,
that I'm talking about the custom-event syntax, not the regular
one-liner syntax:
class MyClass
{
Object myLock;
EventHandler _completed;
public event EventHandler Completed
{
add {
lock (myLock) {
_completed =
(EventHandler)Delegate.Combine(_completed, value);
// update some other state
}
}
remove {
lock(myLock) {
_completed =
(EventHandler)Delegate.Remove(_completed, value);
// update some other state
}
}
}
void RaiseCompleted()
{
EventHandler c = null;
lock(myLock) {
c = _completed;
}
if(c != null)
c();
}
}
More information about the Digitalmars-d
mailing list