Win Service & Timer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rajesh Abraham

    #1

    Win Service & Timer

    I have a timer in my Windows Service project and I am
    trying to do some processing on the tick event of the
    timer but this event does not seesms to be raised. Below
    is some code segment. Any Idea?

    Thanks,

    Rajesh Abraham

    -----Code Below------

    private void InitializeCompo nent()
    {
    this.components = new
    System.Componen tModel.Containe r();
    this.timerTermi nator = new
    System.Windows. Forms.Timer(thi s.components);
    //
    // timerTerminator
    //
    this.timerTermi nator.Enabled =
    true;
    this.timerTermi nator.Tick += new
    System.EventHan dler(this.timer Terminator_Tick );
    //
    // TerminatorServi ce
    //
    this.ServiceNam e = "TermSrv";

    }



    private void timerTerminator _Tick(object sender,
    System.EventArg s e)
    {

    System.IO.File. Create(@"c:\tim ertick.txt");

    TerminatorBis.T erminate();
    }
  • Dan Cimpoiesu

    #2
    Re: Win Service & Timer

    Try using the Timer class from System.Threadin g

    Hope this helps
    Dan Cimpoiesu

    "Rajesh Abraham" <chacko97@hotma il.com> wrote in message
    news:16d401c386 63$a9b5bcd0$a40 1280a@phx.gbl.. .[color=blue]
    > I have a timer in my Windows Service project and I am
    > trying to do some processing on the tick event of the
    > timer but this event does not seesms to be raised. Below
    > is some code segment. Any Idea?
    >
    > Thanks,
    >
    > Rajesh Abraham
    >
    > -----Code Below------
    >
    > private void InitializeCompo nent()
    > {
    > this.components = new
    > System.Componen tModel.Containe r();
    > this.timerTermi nator = new
    > System.Windows. Forms.Timer(thi s.components);
    > //
    > // timerTerminator
    > //
    > this.timerTermi nator.Enabled =
    > true;
    > this.timerTermi nator.Tick += new
    > System.EventHan dler(this.timer Terminator_Tick );
    > //
    > // TerminatorServi ce
    > //
    > this.ServiceNam e = "TermSrv";
    >
    > }
    >
    >
    >
    > private void timerTerminator _Tick(object sender,
    > System.EventArg s e)
    > {
    >
    > System.IO.File. Create(@"c:\tim ertick.txt");
    >
    > TerminatorBis.T erminate();
    > }[/color]


    Comment

    • Ignacio Machin

      #3
      Re: Win Service &amp; Timer

      Hi,

      I would use the System.Timers.T imer
      instead of System.Windows. Timer the latter is intended to be used with
      windows forms, and if the memory do not fail me I think that I also had my
      troubles dealing with it and a window service.

      Two other things:
      1- The event of the System.Timers.T imer is different that the one from
      system.windows:
      timer.Elapsed += new ElapsedEventHan dler( ... )
      2- Use the timer.Start() or Enabled=true to start raising the Elapsed event.

      Hope this help,

      --
      Ignacio Machin,
      ignacio.machin AT dot.state.fl.us
      Florida Department Of Transportation

      "Rajesh Abraham" <chacko97@hotma il.com> wrote in message
      news:16d401c386 63$a9b5bcd0$a40 1280a@phx.gbl.. .[color=blue]
      > I have a timer in my Windows Service project and I am
      > trying to do some processing on the tick event of the
      > timer but this event does not seesms to be raised. Below
      > is some code segment. Any Idea?
      >
      > Thanks,
      >
      > Rajesh Abraham
      >
      > -----Code Below------
      >
      > private void InitializeCompo nent()
      > {
      > this.components = new
      > System.Componen tModel.Containe r();
      > this.timerTermi nator = new
      > System.Windows. Forms.Timer(thi s.components);
      > //
      > // timerTerminator
      > //
      > this.timerTermi nator.Enabled =
      > true;
      > this.timerTermi nator.Tick += new
      > System.EventHan dler(this.timer Terminator_Tick );
      > //
      > // TerminatorServi ce
      > //
      > this.ServiceNam e = "TermSrv";
      >
      > }
      >
      >
      >
      > private void timerTerminator _Tick(object sender,
      > System.EventArg s e)
      > {
      >
      > System.IO.File. Create(@"c:\tim ertick.txt");
      >
      > TerminatorBis.T erminate();
      > }[/color]


      Comment

      Working...