I have a thread that connects to two network resources. Each time I attempt a connection, it can take 10 seconds for a reply.
void MyThread()
{
//this takes ten seconds
Resource r1 = MySystem.GetResource(ipAddress1);
//this takes ten seconds
Resource r2 = MySystem.GetResource(ipAddress2);
//do stuff with ep1 and ep2
}
Total time is twenty seconds, but I'd really like it to take only ten seconds -- launching threads each time I call GetResource, receiving a reply and then joining each thread to return control.
What's the best way to do this? Launch two threads that each return a value? Anonymous methods that take references to local variables? My head is spinning. Code is appreciated.