check time of day and do something

I need to add in a feature to check the time every few seconds or something and if is midnight, then logoff from the application.

So it is a one-shot program?
Since if it logs off, then it can’t be running to check the time

Why not use the task scheduling built into which ever OS you are using

Richard if you are looking for an in-app Xplat solution you could create a timer with a set of functions to achieve this? Alternatively you could also create a console app to loop properly and to check time and based on results you could have it talk to your other app via file, TCP/IP socket, or HTTPS socket.

basically my client tend to leave the program open when they leave the office at the end of the day causing me grieve when coming to removing the old program before installing the new program. Since i can’t delete, i would not be able to install the new one,and subsequently he client get some weird message and unable to go into the system.

once my program is close, it does not need to check again.

i was thinking about timer too… maybe on the main menu screen (which is open all the time) what is the best length of time to check??

i never done any console program ever. how do i start the console app and closing the console app. Can i called the console app when my main app started and close the console when main app is close?

how do this console program close the my Artscene application when the time is met??

which way is better?? using console app or main app for checking the time.

Timer in the main app. Check every X minutes. Or hourly, if the granularity is “sometime between midnight and 6 am, log off.”

[quote=213420:@Richard Duke]i was thinking about timer too… maybe on the main menu screen (which is open all the time) what is the best length of time to check??

i never done any console program ever. how do i start the console app and closing the console app. Can i called the console app when my main app started and close the console when main app is close?

how do this console program close the my Artscene application when the time is met??[/quote]

Well many could argue of many Pros/Cons for Console helper app to do this vs. in-app timers. I can say that the in-app timer way is easier unless you want this function to occur when your main app is closed.

I would recommend creating a subclass of a timer so you can instantiate it in code instead of tying it to a window that would most likely close.

For example you could create a Module called Common_Module that you could apply a global sub-classed timer property that you can kick off as mode=timer.mutiple during your app.open or somewhere when your app fires.

This would give your timer an autonomous capability for you throughout your app while its open.

I would check the current time at program opening, and set up the period of a single event timer accordingly. For instance if the program is launched at 9:00 AM, the period is 28,800,000 to turn quit the app at 5:00 PM. 1000 6060*8.

When you get close to 5:00 PM, in order to avoid a user to have the app shut down on him, you can also push back the timer each time he moves the mouse, for instance 30 minutes or so.

After 30 minutes without a mouse move, which implies the user is inactive, then quit will happen.

ok… i already create a class for the timer with the action event that check for the time and then quit if the condition is met.

how do i call the new class?? currently i have to put the timer into the windows that is always open.

[quote=213506:@Richard Duke]ok… i already create a class for the timer with the action event that check for the time and then quit if the condition is met.

how do i call the new class?? currently i have to put the timer into the windows that is always open.[/quote]

Since you know the time at which you want to quit the app, it is not necessary to keep checking the current time.

I would put the timer in App instead. You have to add it as a property, then initialize it in App.Open, and use AddHandler to point to a method. That way it will not need any window.

See http://documentation.xojo.com/index.php/Addhandler where there is precisely an example with a timer.

so how did the app know it is time to close then?

  • When the app starts you get the current time
  • Get the time difference between that time and shutdown time
  • Set a timer to quit with a period of shutdown time minus present time

I tried to explain that above :

MIcheal, Thanks for help. I got it working now.

You’re welcome. Glad to have been of assistance :slight_smile:

i have put the code to close the application at 11:55pm to most of my application. Work very well since i can do my update the my client’s application on the server without asking them to logoff. Before this, i always have problem with replacing the program.