You need the visibility of the parameters not for the timer itself, but just for the timer callback. A timer callback can be an instance method of some class. As all instance method, it can access to the (hidden) reference "this" which is the reference to some instance of the class where you callback is declared. As "this" references the instance of whole class, you can put all your parameters in this class, so the callback method will directly access them.
Let's illustrate it on a simple example.
using System.Threading;
internal class DatabaseTransfer {}
internal class TimedProcessor {
TimedProcessor() {
Timer = new Timer(TimerCallback);
}
System.Threading.Timer Timer;
void TimerCallback(object state) {
if (this.Row != 0) {}
this.DatabaseTransfer.
}
DatabaseTransfer DatabaseTransfer;
int Row, DueTime, Interval;
}
I don't know what you need to do int the timer callback
TimeCallback
. method. I just illustrated, that it can access all instance or static members of the same instance of
TimedProcessor
. Note, that I put an instance of the
Timer
in the same class only for simplicity. This class can be&hellop; well, anything. The
Timer
instance can be in any other class; the only important point here is that
TimerCallback
is the instance method and this method is put in the same class where your "parameters" are.
The qualification prefix "this." in this particular example is redundant; and you can omit it as it is implied. I put it in the code just to make my explanations more clear.
Problem solved.
I would also bring to your attention that in most cases timers should not be used, as an extra thread can do the same job in much more robust and safe way and easier to program. Please see my past answer where I explain it:
Timer Threading in C#[
^].
—SA