Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. ActiveX and Windows Service

ActiveX and Windows Service

Scheduled Pinned Locked Moved C#
comhelpquestion
6 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Guillermo Rivero
    wrote on last edited by
    #1

    Hi guys. I'm building a windows service that uses an ActiveX object. When I try to instantiate the ActiveX I get this error. Could not instantiate ActiveX control 'XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX' because the current thread is not in a single-threaded apartment. I've changed the thread apartment style in the service, instantiated the ActiveX in a separate STA thread and still get the error. Have any of you been in a similar situation ? if so, have you found a solution ? Thanks in advance

    Free your mind...

    J 1 Reply Last reply
    0
    • G Guillermo Rivero

      Hi guys. I'm building a windows service that uses an ActiveX object. When I try to instantiate the ActiveX I get this error. Could not instantiate ActiveX control 'XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX' because the current thread is not in a single-threaded apartment. I've changed the thread apartment style in the service, instantiated the ActiveX in a separate STA thread and still get the error. Have any of you been in a similar situation ? if so, have you found a solution ? Thanks in advance

      Free your mind...

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      Judging by the hits on Google, you're not the first to encounter this problem. Have you tried doing a search for activeX STA? That said, it seems odd that you'd want to instantiate ActiveX UI stuff in a Windows Service. Is this absolutely required? Could the service instead spawn some regular application with that uses the AX control?

      Tech, life, family, faith: Give me a visit. I'm currently blogging about: No, Not I - A poem by Holocaust escapee, chief rabbi, and Messiah-follower Daniel Zion The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

      G 1 Reply Last reply
      0
      • J Judah Gabriel Himango

        Judging by the hits on Google, you're not the first to encounter this problem. Have you tried doing a search for activeX STA? That said, it seems odd that you'd want to instantiate ActiveX UI stuff in a Windows Service. Is this absolutely required? Could the service instead spawn some regular application with that uses the AX control?

        Tech, life, family, faith: Give me a visit. I'm currently blogging about: No, Not I - A poem by Holocaust escapee, chief rabbi, and Messiah-follower Daniel Zion The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

        G Offline
        G Offline
        Guillermo Rivero
        wrote on last edited by
        #3

        Thanks for your reply. I know it looks odd. Let me explain a little further. The main function of the application is to print some kind of files in PDF. The service will "Watch" some folders to see if there are changes on the files, and if there are, a PDF copy (PDF pinting) will be made. To open those files, I need to use the ActiveX supplied by the vendor. All works fine in a Windows Form Application. But the problem comes with the service. How can I achieved what you suggest (Could the service instead spawn some regular application with that uses the AX control?) ? Thanks again

        Free your mind...

        J 1 Reply Last reply
        0
        • G Guillermo Rivero

          Thanks for your reply. I know it looks odd. Let me explain a little further. The main function of the application is to print some kind of files in PDF. The service will "Watch" some folders to see if there are changes on the files, and if there are, a PDF copy (PDF pinting) will be made. To open those files, I need to use the ActiveX supplied by the vendor. All works fine in a Windows Form Application. But the problem comes with the service. How can I achieved what you suggest (Could the service instead spawn some regular application with that uses the AX control?) ? Thanks again

          Free your mind...

          J Offline
          J Offline
          Judah Gabriel Himango
          wrote on last edited by
          #4

          Hi Guillermo Couple things to try: on the entry point of the service, place the [STAThread] attribute. (not sure if you've already tried this). If that doesn't work, perhaps you could have your service simply monitor the folders, and when changes are made on the files, launch a separate process (System.Diagnostics.Process) that is your application that uses the ActiveX control to do heavy lifting.

          Tech, life, family, faith: Give me a visit. I'm currently blogging about: No, Not I - A poem by Holocaust escapee, chief rabbi, and Messiah-follower Daniel Zion The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

          G 2 Replies Last reply
          0
          • J Judah Gabriel Himango

            Hi Guillermo Couple things to try: on the entry point of the service, place the [STAThread] attribute. (not sure if you've already tried this). If that doesn't work, perhaps you could have your service simply monitor the folders, and when changes are made on the files, launch a separate process (System.Diagnostics.Process) that is your application that uses the ActiveX control to do heavy lifting.

            Tech, life, family, faith: Give me a visit. I'm currently blogging about: No, Not I - A poem by Holocaust escapee, chief rabbi, and Messiah-follower Daniel Zion The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

            G Offline
            G Offline
            Guillermo Rivero
            wrote on last edited by
            #5

            Thanks Judah ! You gave me the direction. I tried including [STAThread] attributeand didn't work. Then I tried starting a new thread and setting the appartmentin STA, didn't work. Finally, tried starting the program with ProcessInfo, and the program started !. I'm going to see if the ActiveX works. I'll let you know if it works. Thanks again.

            Free your mind...

            1 Reply Last reply
            0
            • J Judah Gabriel Himango

              Hi Guillermo Couple things to try: on the entry point of the service, place the [STAThread] attribute. (not sure if you've already tried this). If that doesn't work, perhaps you could have your service simply monitor the folders, and when changes are made on the files, launch a separate process (System.Diagnostics.Process) that is your application that uses the ActiveX control to do heavy lifting.

              Tech, life, family, faith: Give me a visit. I'm currently blogging about: No, Not I - A poem by Holocaust escapee, chief rabbi, and Messiah-follower Daniel Zion The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

              G Offline
              G Offline
              Guillermo Rivero
              wrote on last edited by
              #6

              Thanks again Judah. It worked fine. I really appreciate for your guidance. I hope some day I can help you back. See you

              Free your mind...

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups