Windows Service Problems

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?SnVzdCBjbG9zZSB5b3VyIGV5ZXMgYW5kIHNlZQ==

    #1

    Windows Service Problems

    Hello all
    i am 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.Write Entry("In OnStart");
    timer1.Start();
    }

    protected override void OnStop()
    {
    eventLog1.Write Entry("In onStop");
    timer1.Stop();
    }

    protected override void OnContinue()
    {
    eventLog1.Write Entry("In OnContinue");
    timer1.Start();
    }

    FileStream fs;
    StreamWriter sw;
    private void timer1_Tick(obj ect sender, EventArgs e)
    {
    fs = new FileStream(@"C: \tem.txt", FileMode.OpenOr Create, FileAccess.Writ e);
    sw = new StreamWriter(fs );
    sw.BaseStream.S eek(0, SeekOrigin.End) ;
    sw.WriteLine(Da teTime.Now.ToSt ring());
    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/libr...8VS.80%29.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.....

  • =?Utf-8?B?Q2lhcmFuIE8nJ0Rvbm5lbGw=?=

    #2
    RE: Windows Service Problems

    I would say it must have thrown an expection in the logging to the event log.
    Have you checked that part of the code and made sure you are using a valid
    source for the event log entries etc?

    --
    Ciaran O''Donnell



    "Just close your eyes and see" wrote:
    Hello all
    i am 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.Write Entry("In OnStart");
    timer1.Start();
    }
    >
    protected override void OnStop()
    {
    eventLog1.Write Entry("In onStop");
    timer1.Stop();
    }
    >
    protected override void OnContinue()
    {
    eventLog1.Write Entry("In OnContinue");
    timer1.Start();
    }
    >
    FileStream fs;
    StreamWriter sw;
    private void timer1_Tick(obj ect sender, EventArgs e)
    {
    fs = new FileStream(@"C: \tem.txt", FileMode.OpenOr Create, FileAccess.Writ e);
    sw = new StreamWriter(fs );
    sw.BaseStream.S eek(0, SeekOrigin.End) ;
    sw.WriteLine(Da teTime.Now.ToSt ring());
    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/libr...8VS.80%29.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.....
    >

    Comment

    • =?Utf-8?B?SnVzdCBjbG9zZSB5b3VyIGV5ZXMgYW5kIHNlZQ==

      #3
      RE: Windows Service Problems

      here is my constructor code where i had initialized the event log

      InitializeCompo nent();
      if (!EventLog.Sour ceExists("TSNUp datingWebApp"))
      {
      EventLog.Create EventSource("TS NUpdatingWebApp ",
      "TSNUpdatingWeb App");
      }
      eventLog1.Sourc e = "TSNUpdatingWeb App";
      eventLog1.Log = "TSNUpdatingWeb App";

      Comment

      Working...