Wednesday, August 27, 2025

More management email problems

About ten months ago, I wrote1 about problems that one user had when trying to send emails from the OP's management program. Not very much has happened since then, but a few days ago another user had to start sending emails via the auxiliary program ... and they weren't being sent. Files containing the mails were created but the auxiliary program wasn't sending them. I stopped the program and restarted it: the emails were sent. 

So for a few days I would stop the program in the morning then restart it. After a few more days, I thought it better that I ditch the timer in the program and run it every fifteen minutes via a batch file. At this stage I converted the program to be a console program - there was no need for the visual interface. This led to some problems that I had not foreseen, e.g. how would the application know where the email files waiting to be sent were situated? In the original version, I would use the application object to get the program's directory and from that the mail sub-directory, but a console application has no application object. I added a new registry value that would help.

Emails still weren't being sent, but I realised that this was because the program was not waiting for threads to close. This is a problem that I was aware of last year but had forgotten. I solved it in a simple matter: a counter would be incremented every time a thread was launched to send a mail, and decremented when a thread completed. At the end of the program, there is a tight loop that checks if this counter's value is zero; if not, the program sleeps for five seconds then checks again.

Away from the computer, it occurred to me that there was really no need for the emails to be sent via threads. This makes sense in the context of the complete management program: instead of having to wait for an email to be sent, a thread can be launched to do this work whilst the user continues as usual. But in this standalone program, I could just as well send the emails directly instead of via a thread. I'll have to check if I have a program that sends emails directly as opposed to via a thread.

Internal links
[1] 1864



This day in blog history:

Blog #Date TitleTags
19127/08/2009Climbing the learning curveProgramming, Firebird, MBA, dbExpress
19227/08/2009Firebird date fieldsFirebird, dbExpress
62027/08/2013Children of the revolutionDCI Banks, Kindle, Peter Robinson, Ian Rankin, Police procedurals
97027/08/2016The murder detectivesTV series, DCI Banks, Police procedurals
125427/08/2019Yet still more doctoringDBA, Psychology, Martin Seligman, Non-fiction books
180927/08/2024NightnoiseAmbient music, Time signatures

No comments: