Using OCX in a Windows Service

M

Mahesh

Hello there,

I am creating a windows service to monitor wireless terminals and then
transmit the barcodes to the clients. The service needs to use a OCX (I hate
to use OCX in a service but, without OCX, you wont be connected to the base
station). I have added a form and used the ocx on the form only to connect to
the base station.

However, I do get a message in the event log. The service won't start.

Service cannot be started. System.Threading.ThreadStateException: ActiveX
control '244758c6-a002-11d2-b82b-938daecfce37' cannot be instantiated because
the current thread is not in a single-threaded apartment.
at System.Windows.Forms.AxHost..ctor(String clsid, Int32 flags)
at System.Windows.Forms.AxHost..ctor(String clsid)
at AxPLSERVERLib.AxPLServer..ctor()
at WHE.PandD.WHEPLSContainer.InitializeComponent()
at WHE.PandD.WHEPLSContainer..ctor()
at WHE.PandD.WHEDespatchServiceFacade.StartWorking()
at WHE.PandD.WHEDespatchService.OnStart(String[] args)
at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object
state)

For more information, see Help and Support Center at
http://go.microsoft.com/fwlink/events.asp.

I have set [STAThread] attribute and also tried

System.Threading.Thread.CurrentThread.TrySetApartmentState(System.Threading.ApartmentState.STA);

Could you please let me know what I am doing silly here?

Ta
Mahesh
 
G

Gareth Young

Did you ever find a solution to this? We are trying to implement the same thing (using a datalogic OCX COM object) to read barcodes as a server service and dump them into a .txt file.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top