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. Window Service Problems

Window Service Problems

Scheduled Pinned Locked Moved C#
comhelptutorial
5 Posts 3 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.
  • S Offline
    S Offline
    Sabry1905
    wrote on last edited by
    #1

    Hello all i ma trying to learn how to program a windows service application i had add an event log and a timer that used to write to file here is the code protected override void OnStart(string[] args) { eventLog1.WriteEntry("In OnStart"); timer1.Start(); } protected override void OnStop() { eventLog1.WriteEntry("In onStop"); timer1.Stop(); } protected override void OnContinue() { eventLog1.WriteEntry("In OnContinue"); timer1.Start(); } FileStream fs; StreamWriter sw; private void timer1_Tick(object sender, EventArgs e) { fs = new FileStream(@"C:\tem.txt", FileMode.OpenOrCreate, FileAccess.Write); sw = new StreamWriter(fs); sw.BaseStream.Seek(0, SeekOrigin.End); sw.WriteLine(DateTime.Now.ToString()); sw.Flush(); sw.Close(); } and i had added an installer to install the windows service, i followed the instructions that is in the MSDN http://msdn.microsoft.com/en-us/library/zt39148a(VS.80).aspx first it works and installed but when i tried to run it from the windows management console it run and ends immediatly and i got a message telling me that some services closed coze it is not doing anything when i tried to make a new installation package, and reninstall the service, the installation package failed to install the service and give me 2 messages the first one saying that source of the service is on the local machine and finally i got a meesage that the installation is interupted and ended not successfuly plz help to resolve that.....

    P W 2 Replies Last reply
    0
    • S Sabry1905

      Hello all i ma trying to learn how to program a windows service application i had add an event log and a timer that used to write to file here is the code protected override void OnStart(string[] args) { eventLog1.WriteEntry("In OnStart"); timer1.Start(); } protected override void OnStop() { eventLog1.WriteEntry("In onStop"); timer1.Stop(); } protected override void OnContinue() { eventLog1.WriteEntry("In OnContinue"); timer1.Start(); } FileStream fs; StreamWriter sw; private void timer1_Tick(object sender, EventArgs e) { fs = new FileStream(@"C:\tem.txt", FileMode.OpenOrCreate, FileAccess.Write); sw = new StreamWriter(fs); sw.BaseStream.Seek(0, SeekOrigin.End); sw.WriteLine(DateTime.Now.ToString()); sw.Flush(); sw.Close(); } and i had added an installer to install the windows service, i followed the instructions that is in the MSDN http://msdn.microsoft.com/en-us/library/zt39148a(VS.80).aspx first it works and installed but when i tried to run it from the windows management console it run and ends immediatly and i got a message telling me that some services closed coze it is not doing anything when i tried to make a new installation package, and reninstall the service, the installation package failed to install the service and give me 2 messages the first one saying that source of the service is on the local machine and finally i got a meesage that the installation is interupted and ended not successfuly plz help to resolve that.....

      P Offline
      P Offline
      Programm3r
      wrote on last edited by
      #2

      Hi, I think this might help you: Simple Windows Service Example[^] Regards,


      The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^

      S 1 Reply Last reply
      0
      • P Programm3r

        Hi, I think this might help you: Simple Windows Service Example[^] Regards,


        The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^

        S Offline
        S Offline
        Sabry1905
        wrote on last edited by
        #3

        it is most like the same procedures i had did

        P 1 Reply Last reply
        0
        • S Sabry1905

          it is most like the same procedures i had did

          P Offline
          P Offline
          Programm3r
          wrote on last edited by
          #4

          Yes I know that. :wtf: That's why I submitted the post. But the the difference between the post and your code is that the code in the post actually works.


          The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^

          1 Reply Last reply
          0
          • S Sabry1905

            Hello all i ma trying to learn how to program a windows service application i had add an event log and a timer that used to write to file here is the code protected override void OnStart(string[] args) { eventLog1.WriteEntry("In OnStart"); timer1.Start(); } protected override void OnStop() { eventLog1.WriteEntry("In onStop"); timer1.Stop(); } protected override void OnContinue() { eventLog1.WriteEntry("In OnContinue"); timer1.Start(); } FileStream fs; StreamWriter sw; private void timer1_Tick(object sender, EventArgs e) { fs = new FileStream(@"C:\tem.txt", FileMode.OpenOrCreate, FileAccess.Write); sw = new StreamWriter(fs); sw.BaseStream.Seek(0, SeekOrigin.End); sw.WriteLine(DateTime.Now.ToString()); sw.Flush(); sw.Close(); } and i had added an installer to install the windows service, i followed the instructions that is in the MSDN http://msdn.microsoft.com/en-us/library/zt39148a(VS.80).aspx first it works and installed but when i tried to run it from the windows management console it run and ends immediatly and i got a message telling me that some services closed coze it is not doing anything when i tried to make a new installation package, and reninstall the service, the installation package failed to install the service and give me 2 messages the first one saying that source of the service is on the local machine and finally i got a meesage that the installation is interupted and ended not successfuly plz help to resolve that.....

            W Offline
            W Offline
            wurzel_cidermaker
            wrote on last edited by
            #5

            I use the [System.Timers.Timer] object in my Windows Services: - System.Timers.Timer t; void OnStart(string[] args) { t = new System.Timers.Timer(); t.Interval = 1000; t.Elapsed += new System.Timers.ElapsedEventHandler(t_Elapsed); t.Enabled = true; } void t_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { ... }

            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