我有这个简单的方法:
static void Extract()
{
Interlocked.Add(ref Program.n, 1);
Console.WriteLine("Currently on: " + n + " Page");
Console.WriteLine("Downloading String...Extract...");
WebClient client = new WebClient();
string html = client.DownloadString("www.something.com&page=" + n);
Console.WriteLine("Proccesing data from string... (Extract)");
}
Run Code Online (Sandbox Code Playgroud)
我想Extract()一次调用几次方法,我尝试了这个:
while(n<3411)
{
var tasks = new List<Task>();
for (int x = 0; x < 7; x++)
{
tasks.Add(Task.Factory.StartNew(new Action(Extract)));
}
Task.WaitAll(tasks);
}
Run Code Online (Sandbox Code Playgroud)
但我得到错误
严重级代码描述项目文件行抑制状态错误CS1503参数1:无法从'System.Collections.Generic.List'转换为'System.Threading.Tasks.Task'RecipeCommunity_Users C:\ Users\xxx\AppData\Local\Temporary Projects\Community_Users\Program.cs 24有效
我如何Extract()一次多次调用方法?