As suggested by assylias I have modified my code to run requests in several threads. In case you need to do so, these are some valuable informations :
1- Create a thread-safe request procedure and assign differents requestID
to your requests. Pass these arguments to processResponseEvent
via the eventloop
function. This will allow you to make a check regarding the message you are receiving by using a simple condition:
if (msg.CorrelationID != requestID)
{
System.Console.WriteLine("WRONG ID ");
return;
}
2- Make your request in parallel, meaning you enclosed the aforementioned request in a loop such as :
WaitHandle[] waitHandles = new WaitHandle[numOfThreads];
for (int i = 0; i < numOfThreads; i++)
{
var j = i;
var handle = new EventWaitHandle(false, EventResetMode.ManualReset);
var thread = new Thread(() =>
{
/// CALL HERE YOU REQUEST PROCEDURE FROM STEP 1
handle.Set();
});
waitHandles[j] = handle;
thread.Start();
}
foreach (var ee in waitHandles)
ee.WaitOne();
At the end it won't increase the waiting time for each request but since your are performing a bunch of them together you'll still save a LOT of time.
Ps: you can use the variable i
(from for (int i = 0; i < numOfThreads; i++)
) as requestID
.