on 09-18-2008 8:21 PM
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
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
User | Count |
---|---|
99 | |
11 | |
10 | |
6 | |
5 | |
5 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.