c# - How can I set the COM apartment state for code loaded with `AppDomain.ExecuteAssembly`? -


when create thread, have option of setting com apartment state explicitly before start it. example:

// using system.threading; var thread = new thread(…); thread.setapartmentstate(apartmentstate.sta); thread.start(); 

but when create appdomain , load code it, seem have no explicit control on thread creation, have no way of calling setapartmentstate:

// using system; var pluginappdomain = appdomain.create("pluginappdomain"); pluginappdomain.executeassembly(@"plugin.dll"); 

is there way specify main/entry thread created inside appdomain should use specific com apartment state?

i know plugin.dll's main entry method marked [stathread] or [mtathread] attribute; let's assume plugin.dll not explicitly declare or set com apartment state, , cannot change plugin.dll.

i re-posting hans passant's comment above answer since answers of question:

"no, creating [app domain] not create thread. executing state of thread made appdomain.create() call. not enough, cannot uphold sta promise. you'll need more code in [app domain] take care of this, thread creation code , application.run() call needs operate in [app domain]."


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -