我现在有以下代码。它可以正常工作,但picturesDownloaded
不会更新。在这 5 秒内,未调用 sendDatapicturesDownloaded
获取另一个值。每次计时器运行时如何刷新它?所以这obj.ToString()
将是正确的值。
有一点picturesDownloaded
得到值“11”,但object obj
仍然有值“0”。
public static volatile string picturesDownloaded = "0";
System.Threading.Timer timer = new System.Threading.Timer(sendData, picturesDownloaded, 1000 * 5, 1000 * 5);
public static void sendData(object obj)
{
WebClient wc = new WebClient();
string imageCountJson = wc.DownloadString("http://******/u.php?count=" + obj.ToString());
}