Strange Behaviour Over Windows Server in C#?

Discussion in 'Microsoft Dot NET' started by nigil, Jul 15, 2003.

  1. nigil

    nigil Guest

    hi guys..

    anyone encounter this problem ?,... here it's goes.
    look at the Start and Stop Method. I have set the variable str_Value="Stop
    Command Triggerred"
    on the Stop Function. then Start the Service again.. by right the
    EventLog.WriteEntry(str_Value) should be
    writing "Stop Command Triggerred" in the Event Viewer Console cos my string
    variables is declared
    within the constructer and not inside the method. but apparently it turns
    out differently.
    I have got "Default Command Triggerred" from the Event Viewer Console.

    protected override void OnStart(string[] args)
    {
    EventLog.WriteEntry(str_Value);
    }

    protected override void OnStop()
    {
    str_Value="Stop Command Triggerred";
    }


    Full Source Code here -
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Diagnostics;
    using System.ServiceProcess;

    namespace WindowsService
    {
    public class Service1 : System.ServiceProcess.ServiceBase
    {
    private System.ComponentModel.IContainer components;
    private string str_Value="Default Command Triggerred";

    public Service1()
    {
    InitializeComponent();
    }

    static void Main()
    {
    System.ServiceProcess.ServiceBase[] ServicesToRun;
    ServicesToRun = new System.ServiceProcess.ServiceBase[] { new
    Service1() };
    System.ServiceProcess.ServiceBase.Run(ServicesToRun);
    }

    private void InitializeComponent()
    {
    components = new System.ComponentModel.Container();
    this.ServiceName = "Service1";
    }

    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null)
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    }

    protected override void OnStart(string[] args)
    {
    EventLog.WriteEntry(str_Value);
    }

    protected override void OnStop()
    {
    str_Value="Stop Command Triggerred";
    }
    }
     
    nigil, Jul 15, 2003
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. daniel

    dateTimePicker strange behaviour

    daniel, Nov 5, 2003, in forum: Microsoft Dot NET
    Replies:
    2
    Views:
    206
    Guest
    Nov 5, 2003
  2. serge calderara

    Strange behaviour on ByVal parameter ???

    serge calderara, Nov 26, 2003, in forum: Microsoft Dot NET
    Replies:
    3
    Views:
    145
    Jon Skeet [C# MVP]
    Nov 26, 2003
  3. Antonio

    Strange encoding behaviour

    Antonio, Dec 29, 2004, in forum: Microsoft Dot NET
    Replies:
    0
    Views:
    171
    Antonio
    Dec 29, 2004
  4. Daniel O'Brien

    Windows Service - strange stopping behaviour

    Daniel O'Brien, May 7, 2005, in forum: Microsoft Dot NET
    Replies:
    0
    Views:
    162
    Daniel O'Brien
    May 7, 2005
  5. Oleg Medyanik

    command line arguments strange behaviour

    Oleg Medyanik, May 23, 2005, in forum: Microsoft Dot NET
    Replies:
    2
    Views:
    176
    Oleg Medyanik
    May 24, 2005
Loading...

Share This Page