I am migrating an existing .NET class library that uses System.Threading.Timer in a Windows Store app designed for Windows 8.1. The Timer class is available, but several parameters seem to be missing with respect to the corresponding .NET Framework Timer .
In particular, only two constructors are available in the Windows Store version:
public Timer(TimerCallback callback, Object state, int dueTime, int period); public Timer(TimerCallback callback, Object state, TimeSpan dueTime, TimeSpan period);
The .NET Framework contains this additional constructor:
public Timer(TimerCallback callback);
which according to the MSDN documentation sets dueTime and period to Timeout.Infinite and state to a Timer object by itself.
Trying to replace the constructor of single arguments, I "naively" tried to pass the Timer object to one of the Windows 8.1 constructors, for example:
Timer t; t = new Timer(MyCallback, t, Timeout.Infinite, Timeout.Infinite);
but of course this only leads to a compilation error
Using the unassigned local variable 't'
There is also no state setter or SetState method in the Timer class, so state cannot be set after construction.
What can I do to completely imitate the constructor of the complete Timer(TimerCallback) structure Timer(TimerCallback) ?