Console App - DoEvents

So, in my ignorance, I have written a console app that reads MySQL, parses the recordset, makes a HTTPSocket Get to get some data, parse that data and stuff back into the MySQL database. Any errors discovered get sent in an email using SMTPSecureSocket. I have a few boolean flags that get set/unset in the Do/Loop of the app, and when the work is all done, it can then quit happily.

Reading the docs I see DoEvents. I haven’t used that yet, missed it completely, but would that help me. I spawn threads to read each HTTPSocket, and then I send emails using SMTPSecureSockets, and would DoEVents allows those to run and do their magic and allow me to cut down on my boolean flags ?

(or am I missing the plot?)

This is a Linux console app that gets called by Cron every 5 mins.

Thanks

“DoEvents” is something like “goto” - you shouldn’t use it anymore. Try Threads and Timers instead. You will find some samples in your Xojo Example Lib (New Project/ Examples) and also in documentation eBooks.

Not entirely true. For event-driven console applications, i.e. things that stay running, the App’s Run event typically should contain some setup code and when just go into a While loop that calls DoEvents until some condition tells it to quit.

DoEvents is quite fine in Console applications. What you write is only true for GUI applications.

you’re right on that, missed that we re talking about console apps.

Even still, DoEvents and GoTo are not on the same level of “badness.” While GoTo is considered bad-practice but acceptable, DoEvents in a GUI or WE app is always a project breaker.

I wouldn’t use it anymore when creating something new but I wouldn’t touch intact projects either.
@Thom McGrath : Any plan or hint when xojo will make threads running on different CPU cores?

[quote=123449:@Tomas Jakobs]I wouldn’t use it anymore when creating something new but I wouldn’t touch intact projects either.
@Thom McGrath : Any plan or hint when xojo will make threads running on different CPU cores?[/quote]
I’m not with the company anymore, but I’m not aware of any plans anyway.

You need DoEvents in a console app to trigger any timers, since a console app has no main event loop.

Until that feature comes, if it does, helper apps can be a solution…

Yup, I don’t have timers yet, but I spew out a ton of threads with database connections and I increment a variable when each one gets created then decrement when it completes, when variable back to zero, move on.

I then send emails, and I had to put in flags that prevent the app quitting so will add DoEvents to that area and see if it makes it more robust.

Thanks

[quote=123621:@Richard Gorbutt]Yup, I don’t have timers yet, but I spew out a ton of threads with database connections and I increment a variable when each one gets created then decrement when it completes, when variable back to zero, move on.

I then send emails, and I had to put in flags that prevent the app quitting so will add DoEvents to that area and see if it makes it more robust.

Thanks[/quote]
Tons of threads isn’t going to make things run faster
But a simple helper that can run as a separate process can since it is its own process that can run on a different core etc

When I say a ton of threads, each one is based on a user from the database & then checks a server exists, I thread them because if a server isn’t responding or isn’t there, I’m waiting for a timeout. Rather be concurrent than consecutive :slight_smile:

Helpers can be - in fact - concurrent since they are their own process & the OS can schedule them preemptively, they have their own memory space etc
And if one dies / crashes with an exception it won’t take your entire app down