System.Threading.Timer TimerCallback delegate with parameters?
c#, timer
Solution
If you want to pass it once, use a second constructor parameter:
System.Threading.Timer(new TimerCallback(sendData), dldnow, 1000*30, 1000*30);
If you want to access it regularly, you can make a static volatile field:
public static volatile int dldnow;
(volatile is need so that it would be always up to date when accessed from multiple threads)
Problem
I need to pass the following `int dldnow` to sendData static method / delegate. ``` 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); } ```