1
我需要通過以下int dldnow
sendData靜態方法/委託。System.Threading.Timer TimerCallback委託與參數?
public int dldnow;
Timer timer = new Timer(new TimerCallback(sendData), null, 1000*30, 1000*30);
public static void sendData(object obj)
{
string imageCount = (string)dldnow;
string imageCountJson = wc.DownloadString("http://*********/u.php?count=" + imageCount);
}
正如答案中所述,只需將'dldnow'作爲參數'state'(現在你寫'null')。另一件事:你不需要完全寫入新的TimerCallback(sendData)。從C#2開始,您只需編寫'sendData'(這稱爲方法組轉換)。 – 2013-04-10 16:19:32
正確的版本參數刷新http://stackoverflow.com/questions/15931850/timer-callback-delegate-doesnt-get-the-refreshed-value-from-parameter-on-every – 2013-04-10 17:04:57