Use the return of Interlocked.Increment
Related
MODIFY
WalletWasabi.Tests/P2pTests.cs
WalletWasabi.Tests/P2pTests.cs
@@ -167,12 +167,13 @@ namespace WalletWasabi.Tests
private void ConnectedNodes_Added(object sender, NodeEventArgs e)
{
var nodes = sender as NodesCollection;
- if (Interlocked.Increment(ref _nodeCount) == 8)
+ long nodeCount = Interlocked.Increment(ref _nodeCount);
+ if (nodeCount == 8)
{
- Logger.LogTrace<P2pTests>($"Max node count reached: {Interlocked.Read(ref _nodeCount)}.");
+ Logger.LogTrace<P2pTests>($"Max node count reached: {nodeCount}.");
}
- Logger.LogTrace<P2pTests>($"Node count: {Interlocked.Read(ref _nodeCount)}.");
+ Logger.LogTrace<P2pTests>($"Node count: {nodeCount}.");
}
private void ConnectedNodes_Removed(object sender, NodeEventArgs e)

Use the return of Interlocked.Increment
Related https://github.com/zkSNACKs/WalletWasabi/issues/1276