私はWinformsを使用しており、.Net 4.5をターゲットにしています
アイテムがある限り、同時キューを反復したい。私のアプリケーションでは、ユーザーはいつでも並行キューに項目を追加および削除できます。
サンプルコード:
ConcurrentQueue<string> cq = new ConcurrentQueue<string>();
cq.Enqueue("First");
cq.Enqueue("Second");
cq.Enqueue("Third");
cq.Enqueue("Fourth");
cq.Enqueue("Fifth");
private void someMethod(string)
{
//do stuff
}
while (!cq.IsEmpty)
{
//how do I do the code below in a loop?
//inner loop starts here
someMethod(current cq item);
//move to the next item
someMethod(the next cq item);
//move to the next item
someMethod(the next cq item);
.
.
.
//if last item is reached, start from the top
}
while ループの実行中であっても、アプリケーション ユーザーはいつでもキューに項目を追加または削除できることに注意してください。