Hydra - Delphi Threads - Is the following safe?

Hi there,

I have a Delphi Host application, which uses a .NET plugin.

Is the following approach supported/allowed?

The Delphi host application is running several worker threads. Is it safe to call our .NET plugin via Hydra from within these delphi worker threads or do all calls to the .NET plugin have to be made from the main delphi thread?

Of course we are assuming that the .NET functionality provided by the .NET plugin is thread safe.

I have done some tests and so far I have not encountered any problems calling the .NET plugin from the various delphi threads. It just seems to work fine. But somehow in the back of my head I remember something regarding all calls having to be made from within the main thread.

A concrete example:

I have a Hydra wrapper for a .NET class that can parse JSON data sequentially very fast and with a low memory footprint.

I have several delphi threads each containing their own json data.
Each Delphi Thread then instantiates this .NET class via Hydra and parses the data.
So far it has been working fine!

Thank you!

I found the following link in the Hydra documentation which states:

Interfaces and threads
In .Net, you can’t access COM objects created in one thread from another one. All threads that want to use the Host interface must synchronize their calls with the main thread.

However it seems that this restriction is NOT valid for Delphi. In Delphi you CAN access and use COM objects created in different threads. Is this correct?

So far it is working for me. I just want to have confirmation that this is indeed supported.
It would be terrible to rely on my findings to only find out later that it was not supported, and had only worked by chance.

In general it’s true because anything the host class does is not threadsafe. That said if you return an interface and don’t use single thread apartment (and the implementation is safe), using it is from multiple threads is fine. Does that make sense?

@ck,

thanks for the reply.
One part I am unsure about. I do not know which COM apartment model is being used for our objects.

I registered my .NET interface as follows:

[Guid("349615D8-FBE7-449B-B357-C20B219CBBFA"), ComVisible(true)]
  public interface ISomeInterface : IHYCrossPlatformInterface
  {

This interface is returned to Delphi via a Hydra Plugin call.
However I do not know which COM apartment model is being used?

Do you if STA or MTA is used?

Thanks!

STA would have failed already so these interfaces should be fine.