APARTMENTTHREADED vs MULTITHREADED - WeOnlyDo Discussion board

APARTMENTTHREADED vs MULTITHREADED (General questions)

by silverio, Wednesday, June 30, 2010, 10:21 (5259 days ago)

Hi,
I would like to know if there is some internal take care which force the use the wodVPN only in a APARTMENTTHREADED application.

I've a very complex service server at which a lot of telnet applications can connect. Each telnet connection (is a thread) gain a control of a VPN object. The VPN objects are normally created at server startup, stored in a threaded list and used only by a telnet thread a time. However a telnet thread can create new VPN objects in runtime (and store them in server program threaded list) so I neet to change the default threading model from APARTMENTTHREADED to MULTITHREADED, so in each telnet i don't need to call CoInitialize/CoUninitialize and overall the runtime created VPN controls don't disappear (destroy) when I close the telnet thread.

My program is so all synchronized and only a VPN method at time is used by a telnet thread and by only a thread at time. Unfortunately I don't know if change program threading model can break some internal VPN mechanism...

Re: APARTMENTTHREADED vs MULTITHREADED

by Silverio, Wednesday, June 30, 2010, 17:21 (5259 days ago) @ silverio

At this moment I've solved adding a Synchronized method to telnet thread (I use Delphi TThread, TIdPeerThread) which change the cards in the table creating the wodVPN instance in main thread instead of calling thread. In this way I'm sure the wodVPN is running in apartment STE environment.

In any way I would like to know if I wodVPN is thread safe and so if I can use it in many thread using MULTITHREADED (MTE) model.

Re: APARTMENTTHREADED vs MULTITHREADED

by woddrazen, Wednesday, June 30, 2010, 19:19 (5259 days ago) @ Silverio

Hi Silverio,


wodVPN is thread safe, but you need to have it in apartment threaded.

Which means that the component has to be used from the same thread that it was instantiated from.

Hope this helped.

Regards,
Drazen

Re: APARTMENTTHREADED vs MULTITHREADED

by Silverio, Thursday, July 01, 2010, 15:04 (5258 days ago) @ woddrazen


wodVPN is thread safe, but you need to have it in apartment threaded.

Which means that the component has to be used from the same thread that it was instantiated from.

Uhm, thread safe, this is a good news.
I've leaved the MTE envirorment for the STE (many changes to my code).

At this point however all wodVPN objects are created and stored in a TThreadList by main program thread and used each one by a only TIdTCPServer connection thread (TIdPeerThread). This break what you wrote upon the component has to be used from the same thread that it was instantiated from but I hope this don't generate any fault in the system. If the using thread MUST to be the only creating wodVPN object thread I will need to change again my code.

Unfortunately I'm very bad in OLE/COM knowledge so my project draft suffer of missing knowledge about this matter :(

Cross my fingers...