Hi Richard,
I've taken your example, and modified it a bit. The attached app is in Clarion 8 format, I hope that's ok. It should be easy enough to duplicate the procedures in C6 if you need to.
a) I added a key to the email file.
b) I dropped the "Process" window (which was opening and closing a lot) because having a window open and close over and over like that is gonna cause you focus problems and so on. Rather I have a separate Window procedure that just sits there, passing emails through to the threads as needed.
c) I made a new procedure to start all the email threads, really just so that the code is all in one place, and nice and clean. As each thread starts it notifies this procedure which then starts the next one. When all are opened, it closes. You can call this procedure multiple times though if you wanted to increase the value in GLO:EmailThreads
d) The only use of the critical section is around the Queue. The rest of the global variables are longs, and are of the "write once, read multiple times" variety, so don't need a critical section.
e) If there are no emails to send, the ProcessEmails procedure starts a 15 second timer, at which point it checks the Emails file again. You could obviously make this timer much longer.
I hope the code is reasonably straight-forward to follow - it seems to be working ok here, no duplicates or crashes.
Cheers
Bruce
[attachment deleted by admin]