By default, ASP.NET does not allow any STA COM components to run within the page. To run them, you must include the aspcompat = true property in the .aspx file in the @ page instruction. This will switch to the STA thread pool to the STA thread pool, and HTTPCONTEXT and other built-in objects can be used for COM objects. The former is also a performance optimization because it avoids any call to the multi-threaded unit (MTA) to the STA thread.
With STA COM components, it may be greatly harmful and should be avoided as much as possible. If you must use the STA COM components, as in any InteroP scheme, you should perform a large number of calls during execution and send as much information as possible during each call. In addition, be careful not to create any STA COM components during the constructing page. For example, in the following code, the MyStacomponent created by a thread is instantiated when the page is constructed, and the thread is not a STA thread that will run the page. This may have adverse effects on performance because the page must be constructed to complete the encapsulation processing between the MTA and STA threads.