private void RunMultipleThreadsWithRandomAccessCalls(Func<ICacheStorage<Guid, int>, Guid, int> retrievalFunc)
{
var cacheStorage = new CacheStorage<Guid, int>(() => ExpirationPolicy.Duration(TimeSpan.FromMilliseconds(250)));
var threads = new List<Thread>();
for (var i = 0; i < 50; i++)
{
var thread = new Thread(() =>
{
var random = new Random();
for (var j = 0; j < 1000; j++)
{
var randomGuid = _randomGuids[random.Next(0, 9)];
retrievalFunc(cacheStorage, randomGuid);
ThreadHelper.Sleep(10);
}
});
threads.Add(thread);
thread.Start();
}
while (true)
{
var anyThreadAlive = false;
foreach (var thread in threads)
{
if (thread.IsAlive)
{
anyThreadAlive = true;
break;
}
}
if (!anyThreadAlive)
{
break;
}
ThreadHelper.Sleep(500);
}
}
}