I’m porting an application from Java to C# and I’m facing a problem connected to the different behaviors and features between the java.util.Timer and System.Threading.Timer.
In fact, in the Java version of the Timer class there’s a feature (used in the original code) for scheduling tasks, that is not present in the .NET version, where it is possible to schedule one task (through a delegate function) at a time.
Is there a solution, even a small class-set to implement the feature?
I’ve noticed the existence of several scheduling libraries (an example is Quartz), but I would prefer a solution which would minimize the amount of code to use.
Thank you all! 🙂
You can just use any timer class. For each scheduled task, create a new timer class and just set the Interval property to (ScheduledTime – DateTime.Now).TotalMilliseconds and set the AutoReset property to false (or the Enabeld property to false in the code-behind for the Tick event). That will execute your code once at the specified ScheduledTime.