Create new instances of the object that implements or has a field of type System.Security.Cryptography.ICryptoTransform to avoid sharing it accross multiple threads.

This example demonstrates the dangers of using a shared System.Security.Cryptography.ICryptoTransform in a way that generates incorrect results or may raise an exception.

A simple fix is to change the local variable sha1 being captured by the lambda to be a local variable within the lambda.

  • Microsoft documentation, ThreadStaticAttribute Class.
  • Stack Overflow, Why does SHA1.ComputeHash fail under high load with many threads?.