Click to See Complete Forum and Search --> : Windows service and COM error


gmaden
July 30th, 2003, 09:13 PM
I've written a Windows service in C# that invokes a function (via PInvoke) in an in-house API which, in turn, invokes CoInitialize before loading a COM object. When I attempt to call the function, once the service starts up, I get an error back from the function indicating a previous call to CoInitializeEx had set the threading model to multithread apartment (MTA). I have a client that calls the same API It succeeds because I specify the [STAThread] attribute for the Main method. If I remove the [STAThread] attribute then the client fails with the same error. I added the attribute to the Main method in my class derived from System.ServiceProcess.ServiceBase but to no avail as I still get the same error. Either the attribute is being ignored for Windows services or somewhere else the threading model is set to MTA prempting the attribute setting. Any insight would be greatly appreciated.