What is the purpose of local variable handler
?
Probably none. There is certainly no reason in terms of code-correctness. It appears to be a holdover from the old, pre-null-conditional operator version of the documentation, in which copying the event field ThresholdReached
into a local variable was required in order to safely resolve race conditions between raising the event and any other code that might be unsubscribing from it. As you point out, using the null-conditional operator, the code can simply be one line, invoking via the event field itself.
I only say "probably" because I guess there's a very small chance that the author of the documentation was hoping to achieve some other pedagogical goal with the more-explicit form of the code. But I can't imagine what that might be, and it's obviously interfering with general comprehension of the code (i.e. distracting from the important parts).
I submitted a comment on the page to let Microsoft know of the problem. I think there's also probably a place in the Microsoft Git repo where you can submit an issue for the documentation, if you like.
My experience has been that either way the problem is conveyed to Microsoft, they typically fix the problem in relatively short order. I would guess that in the next couple of weeks, that passage will be fixed, and this question will no longer be relevant. :)