わかりましたので、特定の文字列が参照用に使用する「一時」文字列と異なることを比較することにより、誰かが新しいチャンネルをフォローするたびに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に正しい情報がないなどの理由があるのではないかと考えています。