Is there a way to have a method within a controller class run at a set interval (such as every 30 minutes) without needing the user to interact with the app (so the method is basically timed)?
The particular event I'm looking to have happen is to have my MVC app refresh data from a data connection (ODBC) and thus update both a view in the application and also the SQL database behind the MVC application with any new data that is read from the ODBc
connection (My app works with two separate databases).
Is there a way to have a method within a controller class run at a set interval (such as every 30 minutes) without needing the user to interact with the app (so the method is basically timed)?
You could use Timer class:
public static System.Timers.Timer timer = new System.Timers.Timer(60000); // This will raise the event every one minute.
timer.Enabled = true;
timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
static void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
// Do Your Stuff
}
Best Regards
Cathy
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
12 Points
81 Posts
Having a method run at a given interval "behind the scenes"
Oct 26, 2017 06:16 AM|cbassett|LINK
Is there a way to have a method within a controller class run at a set interval (such as every 30 minutes) without needing the user to interact with the app (so the method is basically timed)?
The particular event I'm looking to have happen is to have my MVC app refresh data from a data connection (ODBC) and thus update both a view in the application and also the SQL database behind the MVC application with any new data that is read from the ODBc connection (My app works with two separate databases).
Star
8670 Points
2882 Posts
Re: Having a method run at a given interval "behind the scenes"
Oct 27, 2017 05:41 AM|Cathy Zou|LINK
Hi cbassett
You could use Timer class:
Best Regards
Cathy
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.