Home All Groups Group Topic Archive Search About

A Service in VB.NET 2005 using a form ?

Author
30 Aug 2006 7:03 AM
hex40
Hi,

I have created a Service with vb.NET 2005 and I want to show a form. How can
I do this? Can I do it like this? Or should'nt I use a form in a service at
all?

Private oMain As Main

    Protected Overrides Sub OnStart(ByVal args() As String)
        ' Code zum Starten des Dienstes hier einfügen. Diese Methode sollte
Vorgänge
        ' ausführen, damit der Dienst gestartet werden kann.

        Try
            oMain = New Main
            oMain.Show()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

If I do so then the form is shown but it say "No response".

Thanks in advance

Kind regards

Stefan

Author
30 Aug 2006 7:36 AM
Pritcham
Hi

>From what I understand you shouldn't have any UI elements in your
service as a service can run irrespective of whether a user is logged
on or not and runs under a system process etc. (could be wrong though).
If you just want the user to be able to interact with your service
(changing settings, start/stop the service etc) then take a look at the
following article that should help.

http://www.devcity.net/Articles/74/1/servicecontroller.aspx


Thanks
Martin
hex40 wrote:
Show quoteHide quote
> Hi,
>
> I have created a Service with vb.NET 2005 and I want to show a form. How can
> I do this? Can I do it like this? Or should'nt I use a form in a service at
> all?
>
> Private oMain As Main
>
>     Protected Overrides Sub OnStart(ByVal args() As String)
>         ' Code zum Starten des Dienstes hier einfügen. Diese Methode sollte
> Vorgänge
>         ' ausführen, damit der Dienst gestartet werden kann.
>
>         Try
>             oMain = New Main
>             oMain.Show()
>         Catch ex As Exception
>             MsgBox(ex.ToString)
>         End Try
>     End Sub
>
> If I do so then the form is shown but it say "No response".
>
> Thanks in advance
>
> Kind regards
>
> Stefan
Author
30 Aug 2006 7:53 AM
hex40
IN VB6 I wrote an exe having several forms. You could run this Program as a
service If you used a ntsvc.ocx. In the property page of the service you had
to say that the service runs under the local system account and that it
interacts with the desktop.
My Service in VB.NET logs on an ftp Server and processes documents. And I
want to show the ftp communication in a form and also what the actual batch
is that is uploaded etc. If I have to write a service without UI then I
should write another program that interacts with my service. How can I manage
this? .NET Remoting? I can't find a simple exmaple for that technique!

Thanks in advance

Stefan

"Pritcham" schrieb:

Show quoteHide quote
> Hi
>
> >From what I understand you shouldn't have any UI elements in your
> service as a service can run irrespective of whether a user is logged
> on or not and runs under a system process etc. (could be wrong though).
>  If you just want the user to be able to interact with your service
> (changing settings, start/stop the service etc) then take a look at the
> following article that should help.
>
> http://www.devcity.net/Articles/74/1/servicecontroller.aspx
>
>
> Thanks
> Martin
> hex40 wrote:
> > Hi,
> >
> > I have created a Service with vb.NET 2005 and I want to show a form. How can
> > I do this? Can I do it like this? Or should'nt I use a form in a service at
> > all?
> >
> > Private oMain As Main
> >
> >     Protected Overrides Sub OnStart(ByVal args() As String)
> >         ' Code zum Starten des Dienstes hier einfügen. Diese Methode sollte
> > Vorgänge
> >         ' ausführen, damit der Dienst gestartet werden kann.
> >
> >         Try
> >             oMain = New Main
> >             oMain.Show()
> >         Catch ex As Exception
> >             MsgBox(ex.ToString)
> >         End Try
> >     End Sub
> >
> > If I do so then the form is shown but it say "No response".
> >
> > Thanks in advance
> >
> > Kind regards
> >
> > Stefan
>
>
Author
30 Aug 2006 8:13 AM
Pritcham
Hi

>From what I understand you can mark a service as interacting with the
desktop from the Services control panel - not sure how you would do
this via code.

As for how you could/would have another program to interact with your
service, this is detailed in the link I suggested (which uses IIS as
its example service).

Again, I'm not overly familiar with service programming so all of this
is info I've gleaned recently while looking at whether creating a
service was the right thing for me (which it wasn't in the end) but if
you need to interact with your service then you can issue custom
commands to your service for it to perform whatever actions you need it
to.

Sorry I can't be of more help

Martin

hex40 wrote:
Show quoteHide quote
> IN VB6 I wrote an exe having several forms. You could run this Program as a
> service If you used a ntsvc.ocx. In the property page of the service you had
> to say that the service runs under the local system account and that it
> interacts with the desktop.
> My Service in VB.NET logs on an ftp Server and processes documents. And I
> want to show the ftp communication in a form and also what the actual batch
> is that is uploaded etc. If I have to write a service without UI then I
> should write another program that interacts with my service. How can I manage
> this? .NET Remoting? I can't find a simple exmaple for that technique!
>
> Thanks in advance
>
> Stefan
>
> "Pritcham" schrieb:
>
> > Hi
> >
> > >From what I understand you shouldn't have any UI elements in your
> > service as a service can run irrespective of whether a user is logged
> > on or not and runs under a system process etc. (could be wrong though).
> >  If you just want the user to be able to interact with your service
> > (changing settings, start/stop the service etc) then take a look at the
> > following article that should help.
> >
> > http://www.devcity.net/Articles/74/1/servicecontroller.aspx
> >
> >
> > Thanks
> > Martin
> > hex40 wrote:
> > > Hi,
> > >
> > > I have created a Service with vb.NET 2005 and I want to show a form. How can
> > > I do this? Can I do it like this? Or should'nt I use a form in a service at
> > > all?
> > >
> > > Private oMain As Main
> > >
> > >     Protected Overrides Sub OnStart(ByVal args() As String)
> > >         ' Code zum Starten des Dienstes hier einfügen. Diese Methode sollte
> > > Vorgänge
> > >         ' ausführen, damit der Dienst gestartet werden kann.
> > >
> > >         Try
> > >             oMain = New Main
> > >             oMain.Show()
> > >         Catch ex As Exception
> > >             MsgBox(ex.ToString)
> > >         End Try
> > >     End Sub
> > >
> > > If I do so then the form is shown but it say "No response".
> > >
> > > Thanks in advance
> > >
> > > Kind regards
> > >
> > > Stefan
> >
> >
Author
30 Aug 2006 2:09 PM
Chris Dunaway
hex40 wrote:
> IN VB6 I wrote an exe having several forms. You could run this Program as a
> service If you used a ntsvc.ocx. In the property page of the service you had
> to say that the service runs under the local system account and that it
> interacts with the desktop.

You can do the same with a service created in VB.Net.  But it is not
recommended.  I also read that in Windows Vista, coming out Q1 next
year, that services will no longer be able to interact with the
desktop.  If you will be upgrading to Vista any time soon, you might
have troubles with your service.  I'm not 100% sure on  this last
point, however.

> My Service in VB.NET logs on an ftp Server and processes documents. And I
> want to show the ftp communication in a form and also what the actual batch
> is that is uploaded etc. If I have to write a service without UI then I
> should write another program that interacts with my service. How can I manage
> this? .NET Remoting? I can't find a simple exmaple for that technique!

I believe that is the recommended approach.  You might also be able to
use named pipes to have your UI program communicate with your service.
I don't have an example handy, but you should be able to Google one up,
though.