single-threaded apartment

Kurt

0
Joined
Feb 14, 2003
Messages
113
Location
Los Angeles
I imported the MSComm ActiveX from VB6 to create a modem object. But C# generates folowing error message when the test program is run. (no compiler warnings)
Code:
An unhandled exception of type System.Threading.ThreadStateException occurred in system.windows.forms.dll

Additional information: Could not instantiate ActiveX control 648a5600-2c6e-101b-82b6-000000000014 because the current thread is not in a single-threaded apartment.

First time I hear about single-threaded apartment, anyone knows what I can do to solve this? Or some general background information...
 
Last edited by a moderator:
Might it be that this has something to do with the project type that I started?

I just want to make a class that I can use in other projects, so I started a ClassLibrary-project in C#. (Visual Studio .NET 2000). I had to add a windows form in the project however, that just acts as a container for the MSComm32.ocx ActiveX. In the Modem class, I then wanted to create a variable of the type AxMSCommLib.AxMSComm and to instantiate that variable by giving a reference to the ActiveX object on the container form. This is necessary because if you only make a variable of that type and instantiate it by running the constructor (New AxMSCommLib.AxMSComm()) the code seems to work, but the control will not be installed/registered on the target machines where the application will run on. By putting it on a form, just like in VB6, Microsoft seems to give a free runtime license to the installing machine.

I recently stepped from VB.NET to C#. In VB.NET I have done this trick before. I just wonder if C# has a problem with that specific ActiveX, or if I maybe should change the project type. Maybe ClassLibrary project should never contain Windows Forms?
 
Back
Top