I use a Logger.pbi file which is runs a thread to write the entries in a file. The log entries are first stored in a list for speed reasons.
In the thread I use FirstElement() to always write the correct entry to the log file.
In the log file the entries were not in correct order

I use AddElement() to add the new entries.
I assumed that AddElement() adds the entry at the end of the list.
THIS IS NOT TRUE.
After reading the help, it became clear that AddElement() is more like InsertElement() it adds an entry behind the current element.
I did not respect this.
My 'fix':
Use LastElement() before using AddElement()
Maybe I change this and use PushListPosition() and PopListPosition() in the logger thread which should be faster.
But this is also tricky, because when FisrtElement() is the only element and I delete it after logging, Pop will crash.
So keep in mind:
AddElement() does not adding the element at the end of the list.
In my case the name AddElement() was misleading.