COM Interop - Multithreading in COM Engagement Packaging

Can multithreading be used in the assembly of the .NET COM wrapper DLL wrapper?

For example, I have a .NET assembly DLL that provides the .NET FTP library for COM. Download features are currently programmed as "best effort." I do not use events or return values ​​to indicate whether it has successfully loaded or loaded, which I can consider later if necessary. Can the .NET assembly (in my really limited sense) simply handle these loading and loading processes in another thread? Assuming this is possible, what would be the result of this if the hosting application was closed before the download or download was completed?

+4
source share
1 answer

Yes, the MSDN article, Managed and Unmanaged Streaming, explains the details. In particular:

Interaction, a common runtime of the language creates and initializes the apartment when the COM object is called. A managed thread can create and enter a single-threaded apartment (STA), which contains only one thread, or a multi-threaded apartment (MTA), which contains one or more threads. When the COM apartment and the streaming apartment are compatible, COM allows the calling thread to make calls directly to the COM object. If the apartments are incompatible, COM creates a compatible apartment and march all calls through the proxy server in the new apartment.


What would be the result of this if the hosting application were closed before the download or download was completed?

Good question. How do you complete the application? If this is just a GUI application that you are closing, I think the main process will continue to run as long as these threads are active. I recommend that you create a test project to confirm the behavior of your application.
+2
source

Source: https://habr.com/ru/post/1347118/


All Articles