using System;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Task task = Display();
task.Wait();
Console.ReadKey();
}
static async Task Display()
{
var process = new Progress<int>((percent) =>
{
Console.WriteLine($"{percent} %");
});
await Task.Run(() =>
{
RunProcess(process);
});
}
static void RunProcess(IProgress<int> process)
{
int n = 0;
for (int i = 1; i <= 10; i++)
{
if (null != process)
C# 使用IProgress实现异步编程报告进度
最新推荐文章于 2023-07-04 07:32:11 发布
本文详细介绍了如何在C#中利用IProgress接口进行异步编程,以便在后台任务执行过程中报告进度。通过实例展示了如何在多线程和Task环境下使用IProgress接口,有效监控和更新异步操作的状态。
摘要由CSDN通过智能技术生成