我正在尝试下载网站源代码,按一下按钮开始检索后,程序将无限卡死
我的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
using (WebClient client = new WebClient())
{
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
string html = client.DownloadString("https://www.finanzen.net/termine/unternehmen/");
MessageBox.Show(html);
}
}
}
}
如何解决此问题?任何帮助表示赞赏:)
你向穷人提出了太多要求MessageBox.Show
。该html
是423,467
字符长。尝试以下方法:
MessageBox.Show(html.Substring(0, Math.Min(html.Length, 1000)));
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句