I’m trying to interact with a third party application but whenever I try and call a method, I get an error message saying System.InvalidOperationException: Operation must be performed on the application thread. The exception is of type System.Reflection.TargetInvocationException and I’m guessing this is because my app is running in a completely separate process. Is there a way to get my program, which is a console application, to start running on the same thread as the third party app?
I’m trying to interact with a third party application but whenever I try and
Share
You can’t get two separate applications to run in a single thread.
If you are trying to interact with some UI controls in your application, you can use
.Invoke()to make sure the relevant code is executed in the UI thread.If you’re trying to manipulate the a third party application, the appropriate solution depends entirely on how you’re interacting with it. Does it provide an API? Sending messages to its window handle? ??
In order to interact with a running instance of another application, you’ll need to use something like remoting (obsolete) or WCF. Essentially, the other application acts as a server, and you have to somehow connect to it. Referencing its assembly, instantiating one of the classes therein defined and calling methods on that instance won’t let you talk to an already-executing process.