这段代码需要一段时间才能执行,尽管我需要做的只是从网站上获取一串文本。我现在有这个
private void main_Load(object sender, EventArgs e)
{
string word = "1.5";
try
{
var url = "http://chipperyman573.com/rtf/textbot.html";
var client = new WebClient();
using (var stream = client.OpenRead(url))
using (var reader = new StreamReader(stream))
{
string downloadedString;
while ((downloadedString = reader.ReadLine()) != null)
{
if (downloadedString == word)
{
//The stuff happens if there's no update
}
else
{
//The stuff that happens if there is an update
}
}
}
}
catch
{
//The stuff that happens if it can't connect to the webpage
}
}
这大约需要 30 秒,而且应该非常快。页面上只有文字。