Useful piece of code when checking for concurrency in your application.
using System;
using System.Threading;
namespace Utilities
{
public class ConcurrencyCheck : IDisposable
{
private static int _concurrencyCount = 0;
public ConcurrencyCheck()
{
var usage = 0;
if ((usage = Interlocked.Increment(ref _concurrencyCount)) != 1)
{
Console.WriteLine("{0} delegates are running concurrently", usage);
}
}
public void Dispose()
{
Interlocked.Decrement(ref _concurrencyCount);
}
}
}
No comments:
Post a Comment