Hi,
Use any structure that can losslessly store your measurement data, specifically I recommend queues, typically used in a producer-consumer architecture. You already have a state machine, so you can use the state machine loop as the consumer loop to write data from a queue to the TDMS. Add the data source as a separate, parallel loop that acquires your measurement data, and puts it in the queue. This way, even if your state machine is busy doing other things such as opening or closing TDMS files, your data does not get lost.
Note that what I mean above is NOT necessarily the Queued State Machine Architecture. In QSM the she state machine transitions are stored in a queue, however in my recommendation above, the queue is independent of the state machine.
If you have further questions, it would be great if we could take a look at your code, maybe there is some simpler issue with the way your are using the TDMS VI-s.
Best Regards,
T Simon
National Instruments
Applications Engineer
Certified LabVIEW Developer - Certified TestStand Architect