단일 스레드 루프를 사용하는 경우 스레드를 수면 상태로 두어 초당 보내는 메시지를 쉽게 제한 할 수있었습니다 (예 : Thread.Sleep(1000/MessagesPerSecond)
).하지만 이제는 병렬 스레드는 더 이상 올바르게 작동하지 않습니다.Parallel.For 사용시 조절
누구나 병렬 스레드를 사용할 때 보내는 메시지를 조절하는 방법에 대한 제안이 있습니까?
Parallel.For(0, NumberOfMessages, delegate(int i) {
// Code here
if (MessagesPerSecond != 0)
Thread.Sleep(1000/MessagesPerSecond);
});