我有代码通过两个并行为每个循环发送 Web 请求。在此方法发生之前添加线程会导致这些任务的执行延迟,还是会实现更多的 Web 请求?
for (int i = 0; i < threads; i++)
{
populateClient(ServerID, debugLog, type, mC);
tasks[i] = Task.Factory.StartNew(() =>
{
testMaps(ServerID, DebugLog, Type, mC.cl, mC.keywords, mC.locations);
});
}
while (tasks.Any(t => !t.IsCompleted)) { } //spin wait
//...
static void testMaps(Int64 serverID, String debugLog, String type, ClientInfo cl,
List<Keyword> keywords,
List<String> locations)
{
Parallel.ForEach(keywords, keyword =>
{
Parallel.ForEach(locations, location =>
{
strFileName = file.DownloadString(query);
//..