Convert event invocations to thread-safe pattern
Convert event invocations to thread-safe pattern

According to Jeffrey Richter (CLR via C#, 3rd edition, pp. 264-265:
"Raising an Event in a Thread-Safe Way"), invoking an event `E` like this:

    if (E != null) { E(...); }

is susceptible to race conditions. At the very least, `E` should be copied
to a temporary variable first. According to Richter, the best, technically
correct way of invoking an event is this:

    var e = Interlocked.CompareExchange(ref E, null, null);
    if (e != null) { e(...); }

This commit converts all event invocations to this pattern.

doubleyewdee/Microsoft.IO.RecyclableMemoryStream,Microsoft/Microsoft.IO.RecyclableMemoryStream,maxwellb/Microsoft.IO.RecyclableMemoryStream