Thank for all your input, I am trying to figure out how I share my code, its has a lot happening in it, normal running is around 45-55 threads. I will try to outline it to start with :-
Threads are :-
Main thread - runs a couple or routines and syncs from PLC threads for any error logs. This also updates a string holding current date and time used in all logs.
Threads that communicate to industrial controllers (PLC's) using libopen62541 (OPC)
Threads that communicate to industrial controllers (PLC's) using libplctag (allen bradley)
Indy TCP threads for clients.
The PLC threads simply write data from the controller to variables in a TRecord. Once initialized the variables dont change except there value.
The clients can request any log data (held in TStringLists) or the variables stored in TRecords.
The system log which holds and connection issues generally seems to be the one I had most issues with, now I have written that side must better so that should be fine moving forwards.
The interesting thing the crash I caught the other night pointed to the current date and time string as it was being written to, the TCP Exception was trying to read it. I didnt think this would do it but once I put it into a critical section, it seems to have solved it.
I do have a question about Critical sections, many of the string lists are being read from and only written to occasionally, is putting these in a critical section the best as I want clients to be able to read them all at once unless it is being written to as I dont want reads to lock the section.
My app is 6000 lines and TBH i am a little embarrassed sharing as I am no expert (self taught, I read as much as I can) but if you want me to I can.