"Vitaly Zayko" <vitaly_at_zayko_dot_net> wrote in message
| 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.