Signaling failure from a Windows console application

I am developing a console app which will be run on a scheduled basis. This application’s task is to connect to another server on the network, and update a local database. The remote database is unavailable at certain times, so I’ve scheduled our task to run outside that time window. Sometimes, though, it seems that the remote host’s unavailability goes well beyond its scheduled time, and my app fails.

So, I was pleased to see an option in the Windows scheduled task manager has an option to retry a specified number of time if/when a scheduled process fails. However, after setting this option up, my application still only ran once last night, even though it returned an error. (Or I think it did)

I’m thinking that perhaps I’m not properly returning the error. When there is an error, my code executes “Quit(n)” where n is a negative integer signaling the error that occurred.

Should I be using positive return values, or am I doing something else wrong here?

on Mac & Linux (UN*Xes), 0 = success, and number 1+ is a failure with a fail code of that number.

Windows, I am not sure if it needs to be negative to be considered failure or not.

Well, I still have not managed to get this working. No matter what non=zero value I pass to application.quit, the Windows Server Task Scheduler thinks that the process has run successfully.

Unless somebody has another suggestion of how to get that mechanism to work, I’m planning to build the functionality into my app. It will run, and if there’s an error, it will wait some number of minutes (15 or so), try again, etc. until there’s either no error or some number of attempts has been exhausted.

My question now is what is the recommended/least consuming of resources way to have it idle for 10-20 minutes? I’m thinking of using delayMBS, but would appreciate hearing any other suggestions or thoughts…

A timer wich quits ?

I use DoEvents. DoEvents(600000) will hibernate your app for 10 mins.

Thanks for the suggestions, Michel and Wayne.

When using doEvents(), Wayne, what do you find the CPU utilization to be? I notice that Christian reports near-zero CPU usage when using delayMBS()

0%. With this technique event the event loop is stopped. Of course this can only be used on non-gui apps whereas delayMBS can be used anywhere.

Thanks, Wayne. I’ll give that a try…

Seems the negative value is not standard in Windows. I have found this
http://www.freedos.org/technotes/technote/207.html

Where error levels are explained :

FIND: 0 found, 1 none found, 2 search not completed CHKDSK: 0 drive okay, 255 any error CHOICE: 0 if aborted, 255 on error, choice value otherwise DEFRAG: 0 success, 1 internal error, 2 disk too full to defrag, 3 aborted by user, 4 general error, 5 read error, 6 write error, 7 FAT allocation error, 8 "memory error", 9 out of memory DELTREE: 0 success, 1 error DISKCOMP: 0 disks are the same, 1 differences found, 2 user aborted with ^C, 3 critical error abort, 4 initialization error (e.g. no such drive?) DISKCOPY: 0 success, 1 non-fatal r/w error, 2 user aborted with ^C, 3 critical error abort, 4 initialization error FORMAT: 0 success, 3 user aborted with ^C, 5 user did not confirm, 4/others signal various fatal errors. KEYB: 0 success, 1 invalid keycode/charset/syntax, 2 keyboard definition file bad or missing, 4 error when communicating with keyboard or monitor, 5 requested charset has not been prepared. MSAV: 86 virus found REPLACE: 0 success, 1 wrong DOS version, 2 source files not found, 3 source or dest. path not found, 5 could not replace files (access violation), 8 not enough memory, 11 syntax error. RESTORE: 0 success, 1 files not found, 3 aborted by ^C, 4 aborted with error SCANDISK: 0 disk okay, 1 syntax error, 2 unexpected out of memory error, 3 aborted by user, 4 all logical checks but not all surface scans done (unless command line option already told to skip surface scan alltogether), 254 errors found but corrected, 255 errors found but not all corrected. SETVER: 0 success, 1 syntax error, 2 file not found, 3 out of memory, 4 invalid version number format, 5 entry in version table not found, 6 setver binary not found, 7 invalid drive, 8 too many command line args, 9 missing command line parameters, 10 error reading setver binary, 11 setver binary corrupt, 12 setver binary has no version table, 13 version tible full, 14 error writing the changed binary. XCOPY: 0 success, 1 no files found to copy, 2 aborted by ^C, 4 initialization error (not enough memory or disk space, invalid drive, or syntax error), 5 disk write error.

The same system of zero meaning no error and different positive values for different errors seem to apply throughout command line programs. You may want to try the same.

Thanks, Michel. I had found a few MSDN documents that had examples using negative values, but I can’t locate them now. I’ve modified my code to return positive error values, and will see what happens the next time it fails. I’ll try to remember to update this thread when I have a definitive answer…