Showing forms within a Windows Service

T

tman

OK so I built this Windows Service which was able to use
MessageBox.Show to present text to the user from within the service. I
had to use a special property though within that method- which is
MessageBoxOptions.ServiceNotification.

Now I'd like to create a custom form and have the service show it, to
administer settings of that service. How do I do this? I tried creating
a simple form and instatiating it then calling Application.run(form) on
it, but nothing happened. No error seemed to occur either because I'm
not getting the output from my exception handler in the event logs...

Any ideas?
 
N

Nicholas Paldino [.NET/C# MVP]

tman,

You don't want to do this. Services do not depend on an interactive
user session in order to run, they are always running, whether or not
someone is logged in or not.

What you want to do is have a program running in the interactive user
session which uses remoting to communicate with the service. The service
can then send a message to the program that is running, and have it display
a form from there.

Hope this helps.
 
T

tman

Thanks for the quick reply Nicholas! Yeah that helps me alot, I was
unsure of how to correctly do this. I wanted to make an app that sits
in System Tray to configure the service like many commercial apps do -
I always thought it was the same app as the service but now I realize
it's separate.

I will look up Remoting to see how that works.

Real quick though, remoting can work both ways right? The service can
also communitcate with this desktop app if it needs to.. can it?

thanks
 
N

Nicholas Paldino [.NET/C# MVP]

tman,

Yes, it can. You can have an object sitting in your app which derives
from MarshalByRefObject, which you pass to your service. Then, when the
service calls a method on that object, it will marshal the call back into
your app.
 

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