cancel
Showing results for 
Search instead for 
Did you mean: 

Alert My Add-On Every hour

Former Member
0 Kudos

Hi,

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

Thank you,

Rune

Edited by: Rune Brattas on Sep 18, 2008 2:21 PM

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

I guess you could use the alert to write a record to a table- and then poll the table in your addon. this would probably create the effect you are looking for.

Former Member
0 Kudos

Nice!

How do I catch the event the table has been used by the alert?

Any code sample?

Thank you,

Rune

Edited by: Rune Brattas on Sep 18, 2008 2:42 PM

Nussi
Active Contributor
0 Kudos

Hi Rune,

i didn't try it so far but you can do it

check the Alert Tables: OALT, OALR or OAIB

maybe somewhere there's the information you need.

lg David

Edited by: David Nussböck on Sep 18, 2008 10:45 PM

former_member201110
Active Contributor
0 Kudos

Hi Rune,

Unless the code you want to run uses the UI API, it's normally better to have a server-side program to trigger a procedure periodically. There are various options on how to do this, either using a .NET timer control or by using Windows Task Scheduler or SQL Agent to schedule the task.

What task do you want to perform? Is there any feedback to the user when the task completes? Is the task user-specific? Bear in mind that running your code in this way (ie scheduling a task within an addon) could be problematic for the user if the task takes a while to run or if it takes control of the UI in some way because your addon would interrupt what they were doing every hour.

Kind Regards,

Owen

Former Member
0 Kudos

Hi Owen,

Thank you very much for your feedback.

I am building a program running in the background updating some tables; no messages to the user, and it runs only one place.

I like to learn all your suggestions; please drop some code snippets...

1) NET timer control

2) Windows Task Scheduler

3) SQL Agent

Thank you,

Rune

former_member201110
Active Contributor
0 Kudos

Hi Rune,

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.

Kind Regards,

Owen

Former Member
0 Kudos

Thank you, Owen,

Wish you a great day!

Thank you,

Rune

Answers (0)