How to keep COM object alive in .NET windows service?

Posted on 2008-11-11
Last Modified: 2012-05-05
I have created windows service which instantiates COM object in OnStart event of the service. While the service OnStart is in process, I can see the COM EXE in running processes (in task manager) but once the service is completely started, the COM instance gets destroyed. I googled on this in which I got an answer to implement STA thread process to instantiate COM object. But after implementing threading, I now get error as "Retrieving the COM class factory for component with CLSID {D66B3D9C-D465-46B8-BFB4-F63F04FB203C} failed due to the following error: 80080005."

Please help me out...
Question by:yatinganesh
    LVL 26

    Expert Comment

    by:Anurag Thakur
    to implement STA in windows service have a look at the foloowing sample
    LVL 26

    Assisted Solution

    by:Anurag Thakur
    the above link might throw an exception on stop i suppose...
    there was one more link for Using COM Interop on a Single Threaded Apartment from a Windows Service on EE

    Accepted Solution

    We found that the COM component we were using was expired. We brought the licensed copy and now it works fine even without threading. Apology for the trouble.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Suggested Solutions

    In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now