kohsuke / com4j

Type-safe Java/COM binding
http://com4j.kohsuke.org/
BSD 2-Clause "Simplified" License
146 stars 78 forks source link

Fix Variant conversion in same ComThread #41

Open vezjakv opened 9 years ago

vezjakv commented 9 years ago

Variant conversion gets blocked when calling from same ComThread. For example, this happens in asynchronous COM event handling when iterating through properties of received COM object in event handler:

ISWbemSink sink = ClassFactory.createSWbemSink();
sink.advise(ISWbemSinkEvents.class,new ISWbemSinkEvents() {
    public void onObjectReady(ISWbemObject object, ISWbemNamedValueSet asyncContext) {
        System.out.println("Received event: " + object.getObjectText_(0));
        for (Com4jObject oprop: object.properties_()) {
           ISWbemProperty prop = oprop.queryInterface(ISWbemProperty.class);
           System.out.println(prop.name() + ": " + prop.value());
        }
    }
});

The above code will block in iterator part when retrieving and converting Variants. The solution is to do conversion in Variant's ComThread if the same as calling ComThread.