IProgress
- IProgress
// Online C# Editor for free
// Write, Edit and Run your C# code using C# Online Compiler
using System;
using System.Threading.Tasks;
public class HelloWorld
{
public static void Main(string[] args)
{
Teste.Load(new ConsoleProgress()).GetAwaiter().GetResult();
}
}
public static class Teste
{
public static async Task Load(IProgress<int> progress = null)
{
var steps = 40;
for (int i = 0; i < steps; i++)
{
await Task.Delay(1000);
progress?.Report((i + 1) * 100 / steps);
}
}
}
public class ConsoleProgress : IProgress<int>
{
public void Report(int value)
{
Console.WriteLine(value);
}
}
