I am trying to use my own C++ class to interact with a COM library that is STA.
The problem we are trying to solve is that a third party application has the STA attribute set to it. The application then creates the C++ service we created and other services (in our case a WCF service) are modifying elements in the service created by the third party STA attribute application. In essence we have Thread1 coming from STA application who creates the service, then Thread2...N coming from WCF which is not in a STA thread state manipulating data held in the service. The STA application doesn't see the changed data and acts as though nothing happened.
So in order to fix it, I am thinking that I have to ensure that all operations contained in my service need to be guaranteed to run on the same thread. The question I have is how to achieve that.
I will show an example of our current code.
Current Service (every method needs to be called on the same thread that it was initially created on)
MyService::MyService()
{
// creates some objects and maybe some other initializing
// Whatever thread (the STA application in this case) this was
// created on needs to be used on all methods, how?
}
ObjectA MyService::GetObject()
{
return anObject;
}
ObjectB MyService::CreateObjectB()
{
// Do some tasks that eventually create object
object = new ObjectB();
return object;
}
void MyService::SomeVoidFunction()
{
// Do some work
}
I am not sure if I can take advantage of the TPL and do this, or do I need to use ThreadPools or something like that?