我在C#中有以下内容
public static void Main()
{
var result = Foo(new Progress<int>(i =>
Console.WriteLine("Progress: " + i)));
Console.WriteLine("Result: " + result);
Console.ReadLine();
}
static int Foo(IProgress<int> progress)
{
for (int i = 0; i < 10; i++)
progress.Report(i);
return 1001;
}
Run Code Online (Sandbox Code Playgroud)
Main的一些输出是:
第一次运行:
Result: 1001
Progress: 4
Progress: 6
Progress: 7
Progress: 8
Progress: 9
Progress: 3
Progress: 0
Progress: 1
Progress: 5
Progress: 2
Run Code Online (Sandbox Code Playgroud)
第二轮:
Progress: 4
Progress: 5
Progress: 6
Progress: 7
Progress: 8
Progress: 9
Progress: 0
Progress: …
Run Code Online (Sandbox Code Playgroud)