STA model and new thread
-
Hello! I want to know how .NET managed threads in STA model application. When I create new thread should I init COM library in some way (like CoInitialize() in C++) or .NET did it for me? Best regards, M.
.NET does it all for you; you don't need to call CoInitialize. Note that if you're using a COM object on a background thread, ensure that the thread is STA. You can do this by calling thread.SetApartmentState before the thread has started executing. Note that the UI thread for Windows Forms (and WPF, I believe) applications are STA by default, so if you created a COM object on that thread, you'll be fine.
Tech, life, family, faith: Give me a visit. I'm currently blogging about: Just F-ing Do It :) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango