C# Windows Service unable to receive COM callback events

S

SPG

Hi,

We have a standard windows app writeen in C# that uses an ActiveX dll to
send us events. This works fine as a Windows app, but as soon as we compile
as a service, no more events.

I have been told that there is no message pump provided to the service, and
therefore the events from the dll cannot be serviced.

Has anyone ever come across this? How did you get around it?
I have tried creating a message pump using Application.Run() but I don't
think I am doing the right thing.

Any help would be greatly appreciated.

Steve
 
N

Nicholas Paldino [.NET/C# MVP]

Steve,

Calling the static Run method on the Application class isn't going to do
anything for you. What you have to do is set the thread up that you are
running your code on to join an apartment. Now, I believe that the calls to
your component for starting, stopping, pausing, etc, etc, will come in on
the same thread, so what you might want to do is set the apartment state
when the service starts (and you MUST do this before you create any COM
components), by setting the ApartmentState property to MTA or STA, depending
on whether or not you want a single-threaded apartment or to join the single
multi-threaded apartment for the process.

Hope this helps.
 

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