首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >运行异步代码AsyncMethodBuilder.cs C#时找不到

运行异步代码AsyncMethodBuilder.cs C#时找不到
EN

Stack Overflow用户
提问于 2019-10-11 23:13:38
回答 1查看 4.5K关注 0票数 4

每当我尝试调试我的代码时,我都会得到错误,但是我无法继续。

AsyncMethodBuilder.cs未找到

背景信息:

我必须压缩大量的文档,并且要花费最少的时间。我有一个压缩库,并且能够同步进行压缩。但是为了加快速度,我想并行压缩文档(一次压缩的文档不是可编程的),这样我就可以适当地利用CPU,并在最佳的时间完成工作。

为了实现上述目标,我按照this链接创建多个任务并等待它们完成

下面是我尝试过的代码。

代码语言:javascript
运行
复制
public static class CompressAllTechniques
    {
        public static void Main()
        {
            GoCallAPIAsync();
        }

        private static async void GoCallAPIAsync()
        {
            try
            {
                List<Task> TaskList = new List<Task>();
// For Sample testing I have taken 4 files and will iterate through them to check the timings
                const string originalFile1 = @"Sample Data\source";
                const string originalFile2 = @"Sample Data\source1";
                const string originalFile3 = @"Sample Data\Original";
                const string originalFile4 = @"Sample Data\Original1";
                List<string> arr = new List<string>() { originalFile1, originalFile2, originalFile3, originalFile4 };
                int noofThreads = 2;       // No of tasks that has to run paralally
                int IterationsCompleted = 0;
                int TotalIterations = 10;
                var temp = arr;
                Console.WriteLine("\n\nProcess Started @ " + DateTime.Now);
                for (int i = 0; i < TotalIterations; i++)
                {
                    if (temp.Count == 0) temp = arr;
                    var sd = temp.Take(noofThreads);

                    foreach (var item in sd)
                    {
                        var LastTask = new Task(() => GoCompress(item, IterationsCompleted));
                        LastTask.Start();
                        TaskList.Add(LastTask);
                    }
                    temp = temp.Except(sd).ToList();

                    await Task.WhenAll(TaskList.ToArray());
                    TaskList.Clear();
                }
                Console.WriteLine("\n\nProcess Completed @ " + DateTime.Now);
                Console.Read();
            }
            catch (Exception ex)
            {
                throw;
            }

        }

        private static void GoCompress(string zdf, int dcnk)
        {
              // Compression Logic
        }        
    }

当我尝试调试上面的代码时,我在Visual中得到了以下异常。

代码语言:javascript
运行
复制
Locating source for 'f:\dd\ndp\clr\src\BCL\system\runtime\compilerservices\AsyncMethodBuilder.cs'. (No checksum.)
The file 'f:\dd\ndp\clr\src\BCL\system\runtime\compilerservices\AsyncMethodBuilder.cs' does not exist.
Looking in script documents for 'f:\dd\ndp\clr\src\BCL\system\runtime\compilerservices\AsyncMethodBuilder.cs'...
Looking in the projects for 'f:\dd\ndp\clr\src\BCL\system\runtime\compilerservices\AsyncMethodBuilder.cs'.
The file was not found in a project.
EN

回答 1

Stack Overflow用户

发布于 2020-10-27 19:21:47

就像@stuartd在上面的注释中说的那样,为调试选项“只启用我的代码”启用(复选框):

我是从谷歌来到这里的,虽然这看起来没有帮助@Sashi,但它解决了我的机器上的这个错误。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58349438

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档