schedule an easy function/c# or to call time
theinvisibleduck
In coresuite customize is there anyway to schedule an easy function to run at a certain time, or to call time in c# or VB?Basically I want to be able to automate making a change every day at a certain time.
Paolo Manfrin
Hi, Yes it is possible!you can create a startup rule of type C# and inside your rule you can specify in C# or call an easy function as you wish.
The snippet is here included:
[CODE]
try
{
System.Timers.Timer tmrTimersTimer = new System.Timers.Timer();
tmrTimersTimer.Interval = 86400 * 1000; // 24 hours
// Anonymous delegate
System.Timers.ElapsedEventHandler handler = new System.Timers.ElapsedEventHandler(delegate(object o, System.Timers.ElapsedEventArgs e)
{
// add your code here
});
tmrTimersTimer.Elapsed += handler;
tmrTimersTimer.Start();
}
catch (Exception ex)
{
StatusBar.WriteError("OPT: WS - Service Call email processor EXCEPTION" + ex.Message);
}
[/CODE]
theinvisibleduck
Paolo,Thank you! Didn't know you could do this. That being said, is there a way to call a specific time of day? It appears that this code is based off of when you log in, which can change from day to day.
Thanks!
Paolo Manfrin
Hi,there are different possibilities.
One is to use the [url="http://msdn.microsoft.com/en-us/library/system.threading.timer.aspx"]http://msdn.microsoft.com/en-us/library/system.threading.timer.aspx[/url] [size=4]class where you can specify a specific date time of the day.[/size]
[size=4]Another possibility is to set a timer which react every "1 hour for example". Then when the rule gets triggered you compare DateTime.Now with the wished activation time. If it is less or equal than 1h you perform the actions otherwise you ignore[/size]
[size=4] [/size][size=4]e.g. in pseudocode
[size=4]Desidered activation time: 23.00[/size]
[size=4]Rule set to run every hour.[/size]
[CODE]
TimeSpan ts = DateTime.Now - (new DateTime(today, 23.00))
if (ts.Minutes <= 60)
// do something
else
// wait
[/CODE]
0
Please sign in to leave a comment.
Comments
0 comments