我創建的一個新類:
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();
}
下載沒問題啊
問題是在類 Satellite 中我無法在 break 上添加斷點;回圈中的行:
if (i == 10)
{
break;
}
我可以在 if 和 close } 上放置一個斷點,但不能在 break 上放置
其次,當它結束提取鏈接時,我可以在回圈結束后在 close } 的底部放置一個斷點,但隨后我看不到 List 項。這就是我所看到的:
有 16 個專案,但大小是 10 個?
大小應該是 10 因為中斷;當 i = 10 但為什么串列有 16 個專案?

當我點擊專案時:

我洗掉了鏈接地址,但有 10 個專案,但還有 6 個空專案。這個空值是從哪里來的?以及為什么我不能在 break 上添加斷點;線 ?為什么當我把滑鼠放在串列上時,我看到的是這種雷克斯 x 而不是物品?
uj5u.com熱心網友回復:
_items是將物體存盤在串列中的內部陣列。它的大小對應于串列的.Capacity屬性。
_items不會通過添加專案來擴展 1:1。當它用完時,它通常會使可用容量增加一倍。源代碼。默認容量是 4(根據來源),所以它會加倍到 8,然后到 16,這正是我們看到的。
你不能暫停執行,break;因為i永遠不會達到 10 的值。
至于紅色的X,旁邊的文字是:
隱式函式求值被用戶關閉
您可以在此處找到解決方案。本質上:進入選項,并在“除錯”下確保選中“啟用屬性評估和其他隱式函式呼叫”。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/339852.html
