By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,889 Members | 1,358 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,889 IT Pros & Developers. It's quick & easy.

Opening form from a windows service

P: n/a
Is it possible to attach a form (C# .NET 2) to windows service and show
it in OnStart event? When I tried to do this in general (new, Show())
way it just didn't do anything nor gave me any errors. I want to use
this form for interaction with the service.
Thanks!
Vit Zayko
Jan 13 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Vitaly Zayko wrote:
Is it possible to attach a form (C# .NET 2) to windows service and show
it in OnStart event? When I tried to do this in general (new, Show())
way it just didn't do anything nor gave me any errors. I want to use
this form for interaction with the service.


You may be able to do it if you change the service to allow interaction
with the desktop - but it's a really bad idea. Services aren't meant to
work like that - they're meant to be entirely in the background.

Instead, your service should expose some kind of control API, probably
over network sockets (eg exposing a remoting service). You could then
write a *separate* Windows Forms app to control it.

Jon

Jan 13 '06 #2

P: n/a
Thanks Jon! Probably I have to do as you said. I was thinking that the
way of direct form using will be easier.
Jan 13 '06 #3

P: n/a

"Vitaly Zayko" <vitaly_at_zayko_dot_net> wrote in message
news:Om**************@TK2MSFTNGP11.phx.gbl...
| Is it possible to attach a form (C# .NET 2) to windows service and show
| it in OnStart event? When I tried to do this in general (new, Show())
| way it just didn't do anything nor gave me any errors. I want to use
| this form for interaction with the service.
| Thanks!
| Vit Zayko

If you feel the need to show something to a user, you first have to ask
yourself if you really need a windows service. Most of the time the answer
is NO.
1. Services are meant to run in the background even when no interactive user
is logged on, they don't have access to the users desktop and they run in a
restricted users security context, so you shouldn't use any UI elements like
Forms in your service.
2. Your OnStart handler should return within 30 seconds, failed to do so
will flag your service as failed to start.

If you want some kind of user interaction with a service you need a second
windows application that uses one of the many IPC mechanisms available in
..NET or windows. The type of IPC you have to select highly depends on the
level of interaction you need, the most appropriate for bi-directional
exchange in .NET is remoting, if you are using v2.0 you can use the
namedpipe remoting channel. If the exchange is uni-directional (eg. service
status, performance info), you may take a look at System.Management
eventing.

Willy.
Jan 13 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.