It was necessary to use a STA thread on an ACE application to send structured annotations to PI. Without the separate thread, the UpdateValues routine would post time and value, but not an annotation when in release mode. It would post annotations only in debug mode under this ACE application.
Unfortunately, I'm finding that after I have sent the first few annotated updates, the timestamp, value, and annotations, which are all passed into the STA thread from ACE class module level private variables, are getting jumbled. I'm doing a for/next loop to update a set of variables. And the annotation is not matching the timestamp and value with the intended annotation. The previous annotation may be associated with the next timestamp and value, for example.
I have no experience in messaging between threads. I believe I need to pass an "I'm done" message or semaphore from the UpdateValues command in the STA thread, before the main thread is allowed to go on and do other updates to the private annotation, value and timestamp variables at the module level.
I hunted the web a bit, and found methods like SendMessage, PostMessage, PostMessageThread, and some custom built thread messaging systems like that shown here: http://www.vbdotnetheaven.com/UploadFile/jscofield/MessageLoop04212005022256AM/MessageLoop.aspx
I wonder if OSIsoft has some of it's own threading utilities or practices that have already been tested and used for situations like this? Do you recommend that I use the above methods, or other OSIsoft threading methods for this task? I am a threading novice. I am barely threading the needle skill-wise, but I think this job calls for an accomplished tailor. Can someone assist with some code samples and advice?