PrincessFrosty
Supreme [H]ardness
- Joined
- May 6, 2009
- Messages
- 5,905
Hi again everyone 
I've come across an interesting problem with a website design, I've found that shared hosting for ASP.NET based websites with a MySQL database don't usually offer support for scheduling stored procedures, mostly due to security.
So I've had to be a bit inventive, I've created a timer in the Global.asax file in the application start which is run when the webserver comes up for the first time, and this starts an asynchronous thread which I want to run a set of stored procedures every hour. So i've used the following code:
I just have code in the WebServiceTimer_Elapsed to connect to the database and call the stored procedures in mysql.
Now this actually works, I've read in many places that it's not supposed to and that ASP.NET doesn't actually support this sort of stuff, but with my development testing and live testing this actually runs in the background independently of anyone browsing the website and does some basic incriments of data in my database.
My problem is that I cannot find a way to reference this asynchronous thread once it's started. I've built an admin page for my website which I want to set an enabled/disabled button for this thread and put in a label so I know if it's currently running or not (or was running when the page loaded). So basically I want to be able to determin if this is currently running and then stop/start it with the click of a button.
Can anyone help me out? I've looked this up a lot and cannot find ASP.NET specific examples because threading isn't something you typically use with ASP.NET as I understand it.
I've come across an interesting problem with a website design, I've found that shared hosting for ASP.NET based websites with a MySQL database don't usually offer support for scheduling stored procedures, mostly due to security.
So I've had to be a bit inventive, I've created a timer in the Global.asax file in the application start which is run when the webserver comes up for the first time, and this starts an asynchronous thread which I want to run a set of stored procedures every hour. So i've used the following code:
Code:
// create new timer
private void CreateTimers()
{
System.Timers.Timer WebServiceTimer = new System.Timers.Timer();
WebServiceTimer.Enabled = true;
WebServiceTimer.Interval = (60000 * 60); // currently 1 hour
WebServiceTimer.Elapsed += new System.Timers.ElapsedEventHandler(WebServiceTimer_Elapsed);
}
I just have code in the WebServiceTimer_Elapsed to connect to the database and call the stored procedures in mysql.
Now this actually works, I've read in many places that it's not supposed to and that ASP.NET doesn't actually support this sort of stuff, but with my development testing and live testing this actually runs in the background independently of anyone browsing the website and does some basic incriments of data in my database.
My problem is that I cannot find a way to reference this asynchronous thread once it's started. I've built an admin page for my website which I want to set an enabled/disabled button for this thread and put in a label so I know if it's currently running or not (or was running when the page loaded). So basically I want to be able to determin if this is currently running and then stop/start it with the click of a button.
Can anyone help me out? I've looked this up a lot and cannot find ASP.NET specific examples because threading isn't something you typically use with ASP.NET as I understand it.