相关疑难解决方法(0)

动作中的C#异步

我想编写一个接受几个参数的方法,包括一个动作和一个重试量并调用它。

所以我有这段代码:

public static IEnumerable<Task> RunWithRetries<T>(List<T> source, int threads, Func<T, Task<bool>> action, int retries, string method)
    {
        object lockObj = new object();
        int index = 0;

        return new Action(async () =>
        {
            while (true)
            {
                T item;
                lock (lockObj)
                {
                    if (index < source.Count)
                    {
                        item = source[index];
                        index++;
                    }
                    else
                        break;
                }

                int retry = retries;
                while (retry > 0)
                {
                    try
                    {
                        bool res = await action(item);
                        if (res)
                            retry = -1;
                        else
                            //sleep if not success..
                            Thread.Sleep(200); …
Run Code Online (Sandbox Code Playgroud)

c# action task

4
推荐指数
1
解决办法
8632
查看次数

标签 统计

action ×1

c# ×1

task ×1