epsilonlabs / emc-ptcim

EMC driver for the PTC Integrity Modeler
Eclipse Public License 1.0
2 stars 0 forks source link

"The application called an interface that was marshalled for a different thread" exception in Jawin #19

Closed zolotas4 closed 7 years ago

zolotas4 commented 7 years ago

When an EVL fix is executed that calls the setter an exception is thrown by Jawin. It is most probably due to calling the setter running on a specific thread from another (the UI) thread.

A possible solution is the creation of a queue of items that should be executed by the setter, population of this queue from the UI thread (or whichever thread called the invoke method) and then execution of the invoke method for each of the items of the queue (using a listener).

kolovos commented 7 years ago

Another option may be to get a fresh copy of the object using its id and set the property of the fresh object instead.

arcanefoam commented 7 years ago

Actually it's more related to threads, as Thanos comments. If you look at the dt plugin,the model configuration dialog has its own COM connection to open the model selection dialog and such. So I guess the EVL fix window needs something similar. I read the jawin multi thread info and it looks very difficult to get working. The problem with having a separate COM connection and ultimately a separate PTC model is that you would have separate caches (i.e. the changes from the fix will not be seen from the model that was validated). Maybe the jawin factory can keep track of the models and return the same instance for models with the same path.

zolotas4 commented 7 years ago

The solution I came up with is the following: I create a custom list that extends ArrayList and overrides the add method. When the setter is called the value that is passed as parameter (to the invoke method) is added to the custom list. The overridden add method of the custom list then calls via a new thread the original invocation method.

It seems to work, not sure about other side effects though. I re-run some simple eol tests I had and they worked as expected but need to investigate more. Do you see any implications that I may miss?

The code is under develop/19.

zolotas4 commented 7 years ago

The above process can be replaced by just including the whole body of the original invoke(Object value) method in a new Thread runnable. Did the changes and pushed the code to develop/19.

zolotas4 commented 7 years ago

N/A anymore after moving to com4j.