好的,所以我有一个程序,通过比较某个字符串与我用作参考的“临时”字符串不同,每当有人新关注频道时,它都会检查 twitch url。但不是每次字符串不同时只输出一条消息,而是卡在输出最新的追随者,然后是第二个最新的追随者,然后是最新的追随者的循环中,等等。
我错过了什么?此外,是否有更好的方法来检查某个字符串是否已更新?
private void DonationListen()
{
try
{
followers = this.donationClient.DownloadString("https://api.twitch.tv/kraken/channels/" + channel.Trim() + "/follows");
donationTimer.Interval = 10000;
donationTimer.Elapsed += new ElapsedEventHandler(CheckUpdates);
donationTimer.Start();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
private void CheckUpdates(object source, ElapsedEventArgs e)
{
donationTimer.Stop();
int startIndex = followers.IndexOf("display_name\":") + 15;
int endIndex = followers.IndexOf(",\"logo", startIndex);
prevFollower = followers.Substring(startIndex, (endIndex - 1) - startIndex);
if (firstRun == true)
{
temp = prevFollower;
}
else if (prevFollower != temp)
{
//New follower detected
temp = prevFollower;
if (updateFollower != null)
{
updateFollower(prevFollower);
}
}
else
{
//Follower is the same as before
}
firstRun = false;
DonationListen();
}
我认为这可能与尝试从 url 获取新字符串的下载字符串有关,但由于它当前正在更新而失败,因此 CheckUpdates 没有正确的信息或其他什么?