471,325 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,325 software developers and data experts.

Opening form from a windows service

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
3 14234
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
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

"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.

Similar topics

2 posts views Thread by Eric Caron | last post: by
14 posts views Thread by D. Alvarado | last post: by
2 posts views Thread by John | last post: by
11 posts views Thread by Andrew Mueller | last post: by
reply views Thread by pintu | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.