Search code examples
c#multithreadingstaapartment-state

How many 'STA' threads can coexist inside a process?


I need multiple STA threads inside my ASP.NET application to use some COM components.

I read somewhere inside each process, only one STA thread can exist. I coded a sample project and made many threads and set their apartment state to STA and they work with COM objects without any exception.

Is it possible to have many STA threads inside a process ?


Solution

  • If your program works with many STA threads, then why do you ask if it works? :) .NET allows you to have any number of STA threads, so it must work. What you read might be true for typical native applications with only one main thread and a message loop, though.