これを行う最善の方法は、作業リストをロードし、リストをランダム化してから、エンド ワーカーによって引き出される何らかの形式のキューにリストを入れることです。
private BlockingCollection<string> GetWorkSoruce()
{
List<string> sourceList = GetListOfFiles(); //How you get your list is up to you.
Shuffle(sourceList); //see http://stackoverflow.com/questions/273313/randomize-a-listt-in-c-sharp
//Create a thread safe queue that many consumers can pull from.
var collection = BlockingCollection<string>(new ConcurrentQueue<string>(sourceList));
collection.CompleteAdding();
return collection;
}
これで、各ワーカー (ユーザー) がキューから抜け出し、作業を行うことができます。キューは ConcurrentQueue であるため、多くのスレッドから多くのワーカーを同時に動作させることができます。
private void WorkerDoWork(BlockingCollection<string> workSource, int itemsToTake)
{
foreach(var imagePath in workSource.GetConsumingEnumerable().Take(itemsToTake))
{
ProcessImage(imagePath);
}
}