首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >什么会导致for / foreach循环中断而不显式调用中断?

什么会导致for / foreach循环中断而不显式调用中断?
EN

Stack Overflow用户
提问于 2022-05-03 12:14:49
回答 2查看 35关注 0票数 0

我有一个持久函数,它调用一个简单地向efcore对象添加行的方法。它不叫分贝保存。

当我跨过代码并进入for循环时,它将立即跳到for循环之后的行。如果我进入调用添加efcore对象,并返回到for循环,它将继续并循环到下一项。如果我按F5让它在不进行调试的情况下进行,它会立即“中断”for循环。

它跳出了我编写//HERE!!!!!!的for循环

我要把我的头发拔出来。

强制性法规:

代码语言:javascript
运行
复制
//foreach (stagingFileMap stagingFileMap in fileMaps)
foreach (stagingFileMap stagingFileMap in fileMaps)
{
    if (ActivitySyncHelper.IsSyncCancelled(aso, _configuration))
    {
        break;
    }

    if (!string.IsNullOrEmpty(stagingFileMap.URL))
    {
        // Ensure the url is valid
        try
        {
            string x = await GetTotalBytes(stagingFileMap.URL);
            double.TryParse(x, out double fileByteCount);

            if (fileByteCount > 0)
            {
                // Create or update the video in vimeo
                if (string.IsNullOrEmpty(stagingFileMap.VimeoId))
                {
                    // Azure won't be ready with its backups, so use confex host for video 'get'
                    string title = stagingFileMap.FileName;
                    if (stagingFileMap.FileName.Length > 127)
                    {
                        title = stagingFileMap.FileName.Substring(0, 127);
                    }

                    Video video = vimeoClient.UploadPullLinkAsync(stagingFileMap.URL, title, stagingFileMap.id, meetingIdFolder.Uri).Result;
                    stagingFileMap.VimeoId = video.Id.ToString();
                    stagingFileMap.VimeoId = video.Id.ToString();
                    //HERE!!!!!!
                    await syncLog.WriteInfoMsg($"Vimeo create {stagingFileMap.FileName}");
                    //HERE!!!!!!
                }
                else
                {
                    // Attempt to pull the existing video and update it

                    if (long.TryParse(stagingFileMap.VimeoId, out long videoId))
                    {
                        Video video = vimeoClient.GetVideoAsync(videoId).Result;
                        if (video.Id.HasValue)
                        {
                            Video res = await vimeoClient.UploadPullReplaceAsync(stagingFileMap.URL, video.Id.Value, fileByteCount);
                            await syncLog.WriteInfoMsg($"Vimeo replace {stagingFileMap.FileName} id {res.Id}");
                        }
                    }

                }

                break;
            }

            

        }
        catch (Exception ex)
        {
            // IDK what to do besides skip it and continue
            // log something once logging works
            await syncLog.WriteErrorMsg(aso, ex.Message);
            await syncLog.Save();
            continue;
        }

        // We need to save here requently because if there is big error, all the work syncing to vimeo will be desync with the DB
        dbContext.Update(stagingFileMap);
        await dbContext.SaveChangesAsync();
        await syncLog.Save();
    }
}
await dbContext.DisposeAsync();
代码语言:javascript
运行
复制
public async Task WriteInfoMsg( string msg)
{
    SyncAttemptDetail sad = new()
    {
        SyncAttemptId = _id,
        Message = msg,
        MsgLevel = SyncAttemptMessageLevel.Info,
        AddDate = DateTime.UtcNow,
        AddUser = "SYSTEM"
    };
    await _dbContext.SyncAttemptDetail.AddAsync(sad);
}
EN

回答 2

Stack Overflow用户

发布于 2022-05-03 12:56:51

我是哑巴。里面确实有个中断命令。

票数 0
EN

Stack Overflow用户

发布于 2022-05-17 21:48:49

await将创建一个任务并立即返回它(调试器也将遵循此路径)。循环将在任务中继续。

若要将调试器附加到任务,请在等待后添加一个断点。

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

https://stackoverflow.com/questions/72099233

复制
相关文章

相似问题

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