Playing with Progress class:
static async Task MyMethodAsync(IProgress<double> progress = null)
{
int done = 0;
while (done<100)
{
if (progress != null)
progress.Report(done);
done++;
}
}
static async Task CallMyMethodAsync()
{
var progress = new Progress<double>();
progress.ProgressChanged += (sender, args) =>
{
Console.WriteLine("progr " + args);
};
await MyMethodAsync(progress);
}
public static void Main()
{
CallMyMethodAsync();
Console.WriteLine("done with caller");
Console.ReadLine();
}
Got output not in correct order:
done with caller
progr 2
progr 3
progr 4
progr 5
progr 6
progr 7
progr 8
progr 9
progr 10
progr 12
progr 11
progr 0
progr 13
progr 16
progr 17
progr 18
progr 19
progr 20
progr 21
progr 22
progr 23
progr 24
progr 25
progr 26
Why and how to achieve correct order?