c# - 为什么我不能在休息时调试;行以及为什么列表包含空项目?
问题描述
我创建的一个新课程:
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();
}
下载的很好。
问题出在卫星类中,我无法在中断处添加断点;循环中的行:
if (i == 10)
{
break;
}
我可以在 if 和 close } 上设置断点,但不能在 break 上
其次,当它结束提取链接时,我可以在循环结束后在 close } 的底部放置一个断点,但是我看不到列表项。这就是我所看到的:
有 16 个项目,但大小是 10?
大小应为 10,因为中断;当 i = 10 但为什么列表有 16 个项目?
当我单击项目时:
我删除了链接地址,但有 10 个项目,但还有 6 个空项目。这个空值是从哪里来的?以及为什么我不能在休息时添加断点;线 ?为什么当我将鼠标放在列表中时,我看到的是这种 rex x 而不是物品?
解决方案
推荐阅读
- arrays - VBA:数组中的名称表
- scala - 使用位掩码对范围内的十进制数进行编码
- java - 如何在 Spring Boot 1.5 中集成 Sleuth 以在较新的 Spring Boot 2.2 中传播跟踪 ID?
- bash - 一个执行函数的衬垫,检查退出状态,如果实际退出代码为 0 或 1,则退出 0
- asp.net - 使用正则表达式将具有动态值且没有占位符的源字符串替换为空字符串
- r - Collapsing multiple factor levels of (messy) character variable in R
- c# - 如何使用函数禁用实例化的预制件
- angular - 如何将已编辑行的值存储在 mat 表的变量中
- r - 在 R 包中使用 tidy eval
- python - django urls 在远程服务器上不起作用