What is the fastest and optimized way to load asynchronous results from various sources in web services?
Dictionary<string, int> readySources = GetReadyHotelSources(member);
eventFlag = new AutoResetEvent[readySources.Count];
int maxTimeOut = 0;
int i = 0;
foreach (KeyValuePair<string, int> activeSource in readySources)
{
maxTimeOut = (int)activeSource.Value > maxTimeOut ? (int)activeSource.Value : maxTimeOut;
i++;
}
int j = 0;
foreach (KeyValuePair<string, WaitCallback> deThread in listOfThreads)
{
if (readySources.ContainsKey(deThread.Key))
{
ThreadPool.QueueUserWorkItem(deThread.Value, j);
eventFlag[j] = new AutoResetEvent(false);
j++;
}
}
if (j != 0)
{
if (!WaitHandle.WaitAll(eventFlag, new TimeSpan(0, 0, maxTimeOut), true))
{
//TODO: audit which thread is timed out
}
}
// combined sources
result = CombineHotelSources();
Now i want to move this code in async mode in web services.