Timer in a console app - Issues with methods

Hello,
I am converting an app from GUI to CLI.

I was able to recycle most of the code but I’m having issues with timers.

In my desktop app, if a method failed to execute, the user would get a notification and the timer would be disabled.

Copy/pasting the same code provides me with an error about the timer not existing unless i convert the method to shared(is that the correct way?) and I cannot run the shared method I need in the timer as I get a “The item does not exist” error in the timer “Action” event handler.

Any idea on how to make it work?

Thanks :slight_smile:

Here you find my sample project Timer in a console app

So using the IDE made timer object is a no go then? Just to know for future projects :slight_smile:

@Joost Rongen I Tried forklifting your project into mine and it fails to compile, the ide demands a delegate(timer) on the row where the method i want to run gets called. Do i need to convert all the methods to Scope:Protected in order to make it work?

I tried a similar project from @Joost Rongen and now it works, I find highly unintuitive that using the gui library to add a timer makes the code uncompilable :frowning:

Please post the code inside the timer action.

Also a console application requires you to call App.DoEvents( TimeToGiveToTheSystemInMilliseconds ) in a loop.

This is the timer action code snippet that works if i create the timer via code(and doesn’t if i create via gui)

[code]If DisableTimer = True Then
DisableTimer = False
Quit
End if

ReadWeb[/code]

DisableTimer is a shared property, ReadWeb is a Method(Public scope)

Not sure what the console app is suppose to do. How do you create via GUI in the console app? Drag from the library into?

The console app is supposed to execute the method ReadWeb every minute unless disabletimer is true (if readweb triggers certain escape conditions, it will set up disabletimer boolean to go true). If i add a timer object using the gui library(via drag&drop) and add the code snippet i pasted earlier to the action event of the customtimer object the compiler will throw a fit about neither disabletimer nor readweb existing. I understand console apps are kinda of a fourth rate citizen in the documentation/ide but if the ide let me add items that won’t work in console mode i might as well stop renewing the console addon and code only on gui projects :V .

When you drag a controller such as a Timer into your console application, it’s just acting as an easier way to subclass that control. You still need to instantiate the subclass that you just created in code.

You can do the same thing in a desktop application. If you drag the control and drop it into the base level contents of your application, it will create a subclass of that control, but if you drop it directly onto a Window, it will do the work of instantiating the object and creating a control without you having to write any code.

It agree that it’s a bit unintuitive when you first start writing console applications. It seems like the concept of something like a Timer should not be lumped into the same group as controls such as buttons, but I’m guessing that there is a good reason behind the design decision.

@Jared Feder I understand that, i just don’t get that i if i need a timer in a console app without doing a manual instancing of the timer obj via code in the run() method(meaning that i know what I am doing), I am required to add stuff mostly undocumented(documentation.xojo.com copy/pasted a couple of lines from the old wiki without explaining how a timer in a console app works, no reference on the manuals included with the IDE, no code examples included with the IDE). Kinda user-unfriendly :frowning:

In any other user-friendly IDE(which is what xojo advertises to be) I would be expecting the IDE to do most of the ground work when I play with prebuild objects in a library and doing everything on my own when i code from scratch. Having to write pretty much everything but the dim customtimer as new timer line from scratch if i use the library provided object seems weird to me. Just my 2c :slight_smile:

When you drag from the Library to the Layout window, you get an object instance created for you. When you drag from the Library to the Navigator, you get a Class created for you. In a console app, there is no Layout, so your only option is creating Classes. Arguably, that isn’t really helpful, but a console app is limited in a lot of ways.

OTOH, if you put your code in the new subclass you create by dragging from the Library, you don’t have to connect the wires in code, so that is somewhat helpful.