Alert My Add-On Every hour
Is it possible to use the Alert manager to triggere a event in my Add-On to run my code every hour?
Or do I need to build a win form outside of B1 with System.Windows.Forms.Timer
Edited by: Rune Brattas on Sep 18, 2008 2:21 PM
Owen Slater replied
1) The .NET framework provides a few timer controls and it is important to get the correct one for your task. If you are going to create a Windows application that will run on the server and which will display a Windows form, you should use the Timer control from the Windows forms control list in Visual Studio (System.Windows.Forms.Timer). If you are writing a Windows service that will run in the background and which doesn't have a user interface, you should use the timer from the Threading library (System.Threading.Timer). These controls offer similar functionality but you must choose the correct timer for your solution or they will not work as expected.
A timer has an interval property that sets a time in milliseconds between each 'tick'. You also have a Start method and a Tick event. The following is a basic example of a timer writing the current time to a textbox every second:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Timer1.Interval = 1000 Timer1.Start() End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick TextBox1.Text += System.DateTime.Now.ToLongTimeString + System.Environment.NewLine End Sub
If you've never used timers before in .NET then a search of MSDN will give you all the examples you'll need.
2) Using Windows Task Scheduler. This is the easiest to implement. Create a .NET Windows application. After the application is started, it should open a DI API connection, perform your task, disconnect the DI API connection and then exit (ie it should close itself down after it has completed the task). Once this application is compiled in to an executable, you can schedule it to be run using Windows Task Scheduler (Control Panel--Scheduled Tasks in Windows Server 2003).
3) SQL 2005 is integrated with .NET so you can invoke .NET dlls from a stored procedure. Therefore, it is possible to write a dll that will perform your task using the DI API and for a stored procedure to call this dll. SQL Agent can then be used to schedule this task. I don't have any examples to hand of how to write this solution but you could try searching the SDN for examples, as I remember it coming up for discussions recently, or check MSDN.