ConcurrentDictionary - Get Snapshot and Clear - Fun C# Code #2

Recently, I was asked to write a 'real-time' calculator and the output value was to be stored in Redis. For legacy reasons, it also had to be stored in the database though, only the latest value had to be kept.

As the calculator was spewing values, they were stored in a ConcurrentDictionary. When the timer was up, I created a new instance of the ConcurrentDictionary and used an Interlocked.Exchange to swap the reference.