为什么我不能在休息时调试;行以及为什么列表包含空项?

Why I can't debug on the break; line and why the List contains null items?

我创建了一个新的 class :

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace Extract
{
    class Satellite
    {
        private List<string> satelliteUrls = new List<string>();
        private string mainUrl = "https://some.com/";
        private string[] statements;

        public async Task DownloadSatelliteAsync()
        {
            using (var client = new WebClient())
            {
                client.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36");

                client.DownloadFileCompleted += (s, e) =>
                {
                    if(e.Error == null)
                    {
                        ExtractLinks();
                    }
                };

                await client.DownloadFileTaskAsync(new Uri(mainUrl), @"d:\Downloaded Images\Satellite\extractfile" + ".txt");
            }
        }

        private void ExtractLinks()
        {
            var file = File.ReadAllText(@"d:\Downloaded Images\images\extractfile" + ".txt");

            int idx = file.IndexOf("arrayImageTimes.push");
            int idx1 = file.IndexOf("</script>", idx);

            string results = file.Substring(idx, idx1 - idx);
            statements = results.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < statements.Length; i++)
            {
                if (i == 10)
                {
                    break;
                }

                string time = statements[i].Split('\'')[1];

                satelliteUrls.Add("https://some.com=" + time);
            }
        }
    }
}

在 Form1 顶部:

Satellite sat;

在 Form1 的构造函数中:

sat = new Satellite();

还有一个按钮点击事件:

private async void btnStart_Click(object sender, EventArgs e)
        {
            lblStatus.Text = "Downloading...";
            await sat.DownloadSatelliteAsync();
        }

正在下载中。

问题出在class Satellite 我不能在断点上加断点;循环中的行:

if (i == 10)
                    {
                        break;
                    }

我可以在 if 和 close 上设置断点 } 但不能在 break 上设置断点

其次,当它结束提取链接时,我可以在循环结束后的底部放置一个断点 } 但我看不到列表项。这是我看到的:

有 16 件商品,但尺寸为 10 件?

大小应为 10,因为中断;当 i = 10 但为什么列表有 16 项?

当我点击项目时:

我删除了链接地址,但有 10 个项目,但还有 6 个空项目。这个 null 是从哪里来的?以及为什么我不能在中断处添加断点;线 ?为什么当我把鼠标放在列表上时,我看到的是这种 rex x 而不是项目?

_items 是存储列表中实体的内部数组。它的大小对应于列表的 .Capacity 属性.

_items 不会通过添加项目来扩展 1:1。当它用完时,它通常会将可用容量增加一倍。 Source code。默认容量是 4(根据来源),所以它会加倍到 8,然后到 16,这正是我们所看到的。

您不能在 break; 上暂停执行,因为 i 永远不会达到值 10。

至于红色的 X,旁边的文字是:

Implicit function evaluation is turned off by the user

您可以找到 的解决方案。本质上:进入选项,并在“调试”下确保选中“启用 属性 评估和其他隐式函数调用”。