Results 1 to 4 of 4

Thread: Add form to a service

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2004
    Posts
    297

    Add form to a service

    Hello,

    I'm trying to open a form on the start event of a service.
    The form opens when I start my service but is not accessable.
    The form looks like it has been crashed.

    Does anyone know how to open a form in a window service?

    I've tried to open it through a thread but the form appears and then quickly disappears.

  2. #2
    Fanatic Member bgmacaw's Avatar
    Join Date
    Mar 2007
    Location
    Atlanta, GA USA
    Posts
    524

    Re: Add form to a service

    Quote Originally Posted by HWijngaarD
    Does anyone know how to open a form in a window service?
    You don't. Windows Services don't have UI's.

    You can create a service control program that communicates with a service though.

  3. #3
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: Add form to a service

    Actually it can be done.
    You must use threads and you must allow the service to interact with the desktop. Services run on a different background and thats why you get your error.
    It's real pain thought. Do it only if you REALLY must use a form like that.

    A different approach will be to have the service pass a value to a resident program (windows application) and from there you can stimulate it to show the form. It's a lot easier.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2004
    Posts
    297

    Re: Add form to a service

    I've got an application that monitors files through an filesystemwatcher (how new is that).
    When a new file has saved it picks it up and transfers it to the database.
    (linq to sql is really handy)
    I got one form on it where I save my settings to my.settings.
    Including the server and the database location.

    Whould you (sapator) help me doing this?
    I allready set the service to interact with the desktop.
    When I put the form.show in a thread I can't keep it open.
    When the threads gone the forms gone...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width