I want use one Timer in my controller to do a specific job.
Below is the code
public class ProductsController : ApiController
{
private readonly System.Timers.Timer _checkTimer = new System.Timers.Timer();
public readonly int CheckTimerInterval = 10 * 30 * 1000;
public ProductsController()
{
_checkTimer.Elapsed += CheckTimerElapsed;
_checkTimer.Interval = this.CheckTimerInterval;
_checkTimer.Enabled = true;
}
private void CheckTimerElapsed(object source, ElapsedEventArgs e)
{
//Do the processing
}
}
But the problem is when ever I call controller a new instance of Timer is created.
I want only one timer instance.Can you please help me to achieve this?
I know using Timer in controller is not a good idea but I do not have other option.I use this controller to assign Requests to an temporary User.In Timer I need to get all jobs and assign it to actual User.
I use this controller to assign Requests to an temporary User.In Timer I need to get all jobs and assign it to actual User.<= that still provides no context. What is the business use case. What is it your are trying to achieve. What is a temporary user, what is a job, why assign jobs to users, what does a timer have to do with jobs or users, etc.