Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Windows Service Application

Windows Service Application

Scheduled Pinned Locked Moved C#
csharpvisual-studioquestion
10 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    a hamidy
    wrote on last edited by
    #1

    Dear All, I have created a very basic and simple windows service application using c# in vs 2005. i have override the "onstart" method and i want that when my service starts a message should appear just to confirm that service starts running. the service starts successfully but no message appears to me. i have tried to write that message to a file but still no file is created. this the code bellow

    protected override void OnStart(string[] args)
    {
    System.Windows.Forms.MessageBox.Show("Service is start...");
    }

    i have googled and used topic in msdn to create window service application. why the message box does not appear when i am starting the service?

    N realJSOPR 2 Replies Last reply
    0
    • A a hamidy

      Dear All, I have created a very basic and simple windows service application using c# in vs 2005. i have override the "onstart" method and i want that when my service starts a message should appear just to confirm that service starts running. the service starts successfully but no message appears to me. i have tried to write that message to a file but still no file is created. this the code bellow

      protected override void OnStart(string[] args)
      {
      System.Windows.Forms.MessageBox.Show("Service is start...");
      }

      i have googled and used topic in msdn to create window service application. why the message box does not appear when i am starting the service?

      N Offline
      N Offline
      Natza Mitzi
      wrote on last edited by
      #2

      Services do not show UI. They are logged in as adifferent user and can not display data to a desktop. You can use Trace.Assert(false,"Hello");

      Natza Mitzi

      A 1 Reply Last reply
      0
      • N Natza Mitzi

        Services do not show UI. They are logged in as adifferent user and can not display data to a desktop. You can use Trace.Assert(false,"Hello");

        Natza Mitzi

        A Offline
        A Offline
        a hamidy
        wrote on last edited by
        #3

        yeah you are right, but if we enable the option "Allow User to Interact with Desktop". we can show UI to the user. i have enabled this option through code, still i need to restart my computer to get affected. I want this without restarting the system.

        N V 2 Replies Last reply
        0
        • A a hamidy

          yeah you are right, but if we enable the option "Allow User to Interact with Desktop". we can show UI to the user. i have enabled this option through code, still i need to restart my computer to get affected. I want this without restarting the system.

          N Offline
          N Offline
          Natza Mitzi
          wrote on last edited by
          #4

          Instead you can use a client application that interacts with the service. Using GUI in services is dangerous

          Natza Mitzi

          A 1 Reply Last reply
          0
          • N Natza Mitzi

            Instead you can use a client application that interacts with the service. Using GUI in services is dangerous

            Natza Mitzi

            A Offline
            A Offline
            a hamidy
            wrote on last edited by
            #5

            can you please have more detail on client application and the interaction way between client and server application. you mean i should call window forms from my installer class.

            N 1 Reply Last reply
            0
            • A a hamidy

              yeah you are right, but if we enable the option "Allow User to Interact with Desktop". we can show UI to the user. i have enabled this option through code, still i need to restart my computer to get affected. I want this without restarting the system.

              V Offline
              V Offline
              Vikram A Punathambekar
              wrote on last edited by
              #6

              Member 6059028 wrote:

              Allow User to Interact with Desktop

              This is VERY bad practice. I believe you can't even do this in Vista.

              Cheers, Vıkram.

              Carpe Diem.

              1 Reply Last reply
              0
              • A a hamidy

                can you please have more detail on client application and the interaction way between client and server application. you mean i should call window forms from my installer class.

                N Offline
                N Offline
                Natza Mitzi
                wrote on last edited by
                #7

                This is a suggestion of implementation. The installer should install both service and application. The service should run independently (treated as a server) and the application should run as a client, post requests and run the service to do what it needs to. The connection between the client application can be implemented using .net remoting and the interaction will be transparent. My preferred way is to implement a service and a client application that runs from the system tray using a notify icon. The client application can have the service controller for starting/stopping/pausing/installing/uninstalling the service. I saw some articles around the code project with samples of notify icons, service controllers and .net remoting. I hope this helps

                Natza Mitzi

                1 Reply Last reply
                0
                • A a hamidy

                  Dear All, I have created a very basic and simple windows service application using c# in vs 2005. i have override the "onstart" method and i want that when my service starts a message should appear just to confirm that service starts running. the service starts successfully but no message appears to me. i have tried to write that message to a file but still no file is created. this the code bellow

                  protected override void OnStart(string[] args)
                  {
                  System.Windows.Forms.MessageBox.Show("Service is start...");
                  }

                  i have googled and used topic in msdn to create window service application. why the message box does not appear when i am starting the service?

                  realJSOPR Offline
                  realJSOPR Offline
                  realJSOP
                  wrote on last edited by
                  #8

                  You can't display interface components in a Windows service.

                  "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                  -----
                  "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

                  P 1 Reply Last reply
                  0
                  • realJSOPR realJSOP

                    You can't display interface components in a Windows service.

                    "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                    -----
                    "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

                    P Offline
                    P Offline
                    Pete OHanlon
                    wrote on last edited by
                    #9

                    You can - you shouldn't, but you can. Windows Services have a property "Interact with desktop" that allows a user to do precisely this - it's yet another crappy design decision.

                    "WPF has many lovers. It's a veritable porn star!" - Josh Smith

                    As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

                    My blog | My articles | MoXAML PowerToys | Onyx

                    realJSOPR 1 Reply Last reply
                    0
                    • P Pete OHanlon

                      You can - you shouldn't, but you can. Windows Services have a property "Interact with desktop" that allows a user to do precisely this - it's yet another crappy design decision.

                      "WPF has many lovers. It's a veritable porn star!" - Josh Smith

                      As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

                      My blog | My articles | MoXAML PowerToys | Onyx

                      realJSOPR Offline
                      realJSOPR Offline
                      realJSOP
                      wrote on last edited by
                      #10

                      I know, but I was trying to keep it as simple as possible for the guy.

                      "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                      -----
                      "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups