A new class I created :
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);
}
}
}
}
In Form1 top :
Satellite sat;
In the constructor in Form1 :
sat = new Satellite();
And a button click event :
private async void btnStart_Click(object sender, EventArgs e)
{
lblStatus.Text = "Downloading...";
await sat.DownloadSatelliteAsync();
}
It's downloading fine.
The problem is in the class Satellite I can't add a breakpoint on the break; line in the loop :
if (i == 10)
{
break;
}
I can put a breakpoint on the if and on the close } but not on the break
Second when it's ending extracting the links I can put a breakpoint at the bottom on the close } after the loop ending but then I can't see the List items. This is what I see :
There is 16 items but the size is 10 ?
The size should be 10 because the break; when i = 10 but why the List have 16 items ?
When I click on the items :
I deleted the links addresses but there are 10 items but then more 6 null items. Where this null's came from ? and why I can't add a breakpoint on the break; line ? why when I put the mous on the List I see this kind of rex x's and not the items ?
CodePudding user response:
_items
is the internal array that stores the entities in your list. Its size corresponds to the list's .Capacity
property.
_items
doesn't expand 1:1 with adding items. It will typically double the available capacity when it runs out. Source code. The default capacity is 4 (according to the source), so it would double to 8, and then to 16, which is exactly what we see.
You can't pause execution on break;
because i
never reaches a value of 10.
As for the red Xs, the text next to it says:
Implicit function evaluation is turned off by the user
You can find the solution to that here. Essentially: go into Options, and under "Debugging" make sure "Enable property evaluation and other implicit function calls" is checked.