ServiceTimer won't fire

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Thirsty Traveler

    ServiceTimer won't fire

    I dropped a Timer object onto a Windows Service and set enabled=true...
    however, it does not appear to be firing. Do I need to do something else?


  • Bob

    #2
    Re: ServiceTimer won't fire

    You probably have to set the Interval value too.

    "Thirsty Traveler" <nfr@nospam.com > wrote in message
    news:%238BSkyta GHA.4580@TK2MSF TNGP03.phx.gbl. ..[color=blue]
    >I dropped a Timer object onto a Windows Service and set enabled=true...
    >however, it does not appear to be firing. Do I need to do something else?
    >[/color]


    Comment

    • r norman

      #3
      Re: ServiceTimer won't fire

      On Fri, 28 Apr 2006 12:20:38 -0400, "Bob" <msgdev@hotmail .com> wrote:
      [color=blue]
      >You probably have to set the Interval value too.
      >
      >"Thirsty Traveler" <nfr@nospam.com > wrote in message
      >news:%238BSkyt aGHA.4580@TK2MS FTNGP03.phx.gbl ...[color=green]
      >>I dropped a Timer object onto a Windows Service and set enabled=true...
      >>however, it does not appear to be firing. Do I need to do something else?
      >>[/color]
      >[/color]

      I have the same problem.

      Working in C++, my InitializeCompo nent() has

      this->ServiceTimer->Enabled = true;
      this->ServiceTimer->Interval = 1000;
      this->ServiceTimer->Tick += gcnew System::EventHa ndler(this,
      &EMuxServiceWin Service::Servic eTimer_Tick);

      My OnStart() has

      ServiceTimer->Start();

      and my OnStop() has

      ServiceTimer->Stop();

      My OnStart, OnStop, and ServiceTimer_Ti ck all have code to write to a
      log file. The OnStart and OnStart logs get written but the timer tick
      log never does.

      I confess to being a complete newbie at DotNet code, although I am
      rather experienced at MFC and Windows32 programming in general, so I
      might be missing something. But what could it be?

      Note: I have also tried putting the timer enable and interval set in
      OnStart.




      Comment

      • Thirsty Traveler

        #4
        Re: ServiceTimer won't fire

        That is pretty much what I have done as well... but the thing won't start.

        "r norman" <NotMyRealEmail @_comcast.net> wrote in message
        news:fil452d4l9 h0vm3sfob1pfhbl 25khcvrsr@4ax.c om...[color=blue]
        > On Fri, 28 Apr 2006 12:20:38 -0400, "Bob" <msgdev@hotmail .com> wrote:
        >[color=green]
        >>You probably have to set the Interval value too.
        >>
        >>"Thirsty Traveler" <nfr@nospam.com > wrote in message
        >>news:%238BSky taGHA.4580@TK2M SFTNGP03.phx.gb l...[color=darkred]
        >>>I dropped a Timer object onto a Windows Service and set enabled=true...
        >>>however, it does not appear to be firing. Do I need to do something else?
        >>>[/color]
        >>[/color]
        >
        > I have the same problem.
        >
        > Working in C++, my InitializeCompo nent() has
        >
        > this->ServiceTimer->Enabled = true;
        > this->ServiceTimer->Interval = 1000;
        > this->ServiceTimer->Tick += gcnew System::EventHa ndler(this,
        > &EMuxServiceWin Service::Servic eTimer_Tick);
        >
        > My OnStart() has
        >
        > ServiceTimer->Start();
        >
        > and my OnStop() has
        >
        > ServiceTimer->Stop();
        >
        > My OnStart, OnStop, and ServiceTimer_Ti ck all have code to write to a
        > log file. The OnStart and OnStart logs get written but the timer tick
        > log never does.
        >
        > I confess to being a complete newbie at DotNet code, although I am
        > rather experienced at MFC and Windows32 programming in general, so I
        > might be missing something. But what could it be?
        >
        > Note: I have also tried putting the timer enable and interval set in
        > OnStart.
        >
        >
        >
        >[/color]


        Comment

        • r norman

          #5
          Re: ServiceTimer won't fire

          On Fri, 28 Apr 2006 11:19:02 -0700, "Thirsty Traveler"
          <nfr@nospam.com > wrote:
          [color=blue]
          >"r norman" <NotMyRealEmail @_comcast.net> wrote in message
          >news:fil452d4l 9h0vm3sfob1pfhb l25khcvrsr@4ax. com...[color=green]
          >> On Fri, 28 Apr 2006 12:20:38 -0400, "Bob" <msgdev@hotmail .com> wrote:
          >>[color=darkred]
          >>>You probably have to set the Interval value too.
          >>>
          >>>"Thirsty Traveler" <nfr@nospam.com > wrote in message
          >>>news:%238BSk ytaGHA.4580@TK2 MSFTNGP03.phx.g bl...
          >>>>I dropped a Timer object onto a Windows Service and set enabled=true...
          >>>>however, it does not appear to be firing. Do I need to do something else?
          >>>>
          >>>[/color]
          >>
          >> I have the same problem.
          >>
          >> Working in C++, my InitializeCompo nent() has
          >>
          >> this->ServiceTimer->Enabled = true;
          >> this->ServiceTimer->Interval = 1000;
          >> this->ServiceTimer->Tick += gcnew System::EventHa ndler(this,
          >> &EMuxServiceWin Service::Servic eTimer_Tick);
          >>
          >> My OnStart() has
          >>
          >> ServiceTimer->Start();
          >>
          >> and my OnStop() has
          >>
          >> ServiceTimer->Stop();
          >>
          >> My OnStart, OnStop, and ServiceTimer_Ti ck all have code to write to a
          >> log file. The OnStart and OnStart logs get written but the timer tick
          >> log never does.
          >>
          >> I confess to being a complete newbie at DotNet code, although I am
          >> rather experienced at MFC and Windows32 programming in general, so I
          >> might be missing something. But what could it be?
          >>
          >> Note: I have also tried putting the timer enable and interval set in
          >> OnStart.
          >>[/color]
          >That is pretty much what I have done as well... but the thing won't start.[/color]

          I have taken the liberty of "correcting " your top-posting.

          Since I am new to DotNet I don't understand what is under the hood.
          But I was going to write my service in good old-fashioned Win32 code
          and, for that, I know that I need a window (albeit invisible for a
          service) and a message pump. My service also includes a SessionSwitch
          event processer which never gets signalled.

          Could it be that we have to add a MessageQueue or something like it to
          the service?


          Comment

          • r norman

            #6
            Re: ServiceTimer won't fire

            On Fri, 28 Apr 2006 15:58:19 -0400, r norman
            <NotMyRealEmail @_comcast.net> wrote:
            [color=blue]
            >On Fri, 28 Apr 2006 11:19:02 -0700, "Thirsty Traveler"
            ><nfr@nospam.co m> wrote:
            >[color=green]
            >>"r norman" <NotMyRealEmail @_comcast.net> wrote in message
            >>news:fil452d4 l9h0vm3sfob1pfh bl25khcvrsr@4ax .com...[color=darkred]
            >>> On Fri, 28 Apr 2006 12:20:38 -0400, "Bob" <msgdev@hotmail .com> wrote:
            >>>
            >>>>You probably have to set the Interval value too.
            >>>>
            >>>>"Thirsty Traveler" <nfr@nospam.com > wrote in message
            >>>>news:%238BS kytaGHA.4580@TK 2MSFTNGP03.phx. gbl...
            >>>>>I dropped a Timer object onto a Windows Service and set enabled=true...
            >>>>>however, it does not appear to be firing. Do I need to do something else?
            >>>>>
            >>>>
            >>>
            >>> I have the same problem.
            >>>
            >>> Working in C++, my InitializeCompo nent() has
            >>>
            >>> this->ServiceTimer->Enabled = true;
            >>> this->ServiceTimer->Interval = 1000;
            >>> this->ServiceTimer->Tick += gcnew System::EventHa ndler(this,
            >>> &EMuxServiceWin Service::Servic eTimer_Tick);
            >>>
            >>> My OnStart() has
            >>>
            >>> ServiceTimer->Start();
            >>>
            >>> and my OnStop() has
            >>>
            >>> ServiceTimer->Stop();
            >>>
            >>> My OnStart, OnStop, and ServiceTimer_Ti ck all have code to write to a
            >>> log file. The OnStart and OnStart logs get written but the timer tick
            >>> log never does.
            >>>
            >>> I confess to being a complete newbie at DotNet code, although I am
            >>> rather experienced at MFC and Windows32 programming in general, so I
            >>> might be missing something. But what could it be?
            >>>
            >>> Note: I have also tried putting the timer enable and interval set in
            >>> OnStart.
            >>>[/color]
            >>That is pretty much what I have done as well... but the thing won't start.[/color]
            >
            >I have taken the liberty of "correcting " your top-posting.
            >
            >Since I am new to DotNet I don't understand what is under the hood.
            >But I was going to write my service in good old-fashioned Win32 code
            >and, for that, I know that I need a window (albeit invisible for a
            >service) and a message pump. My service also includes a SessionSwitch
            >event processer which never gets signalled.
            >
            >Could it be that we have to add a MessageQueue or something like it to
            >the service?
            >[/color]

            OK, MessageQueue is not the right term -- I just saw the words and
            assumed it would be a "Windows message pump" but I was wrong. And I
            found and changed the property
            this->CanHandleSessi onChangeEvent = true;
            but the service still doesn't respond to session change events.



            Comment

            • SR

              #7
              Re: ServiceTimer won't fire

              Try reading this article...



              "Thirsty Traveler" <nfr@nospam.com > wrote in message
              news:ujUXWBvaGH A.4424@TK2MSFTN GP02.phx.gbl...[color=blue]
              > That is pretty much what I have done as well... but the thing won't start.
              >
              > "r norman" <NotMyRealEmail @_comcast.net> wrote in message
              > news:fil452d4l9 h0vm3sfob1pfhbl 25khcvrsr@4ax.c om...[color=green]
              >> On Fri, 28 Apr 2006 12:20:38 -0400, "Bob" <msgdev@hotmail .com> wrote:
              >>[color=darkred]
              >>>You probably have to set the Interval value too.
              >>>
              >>>"Thirsty Traveler" <nfr@nospam.com > wrote in message
              >>>news:%238BSk ytaGHA.4580@TK2 MSFTNGP03.phx.g bl...
              >>>>I dropped a Timer object onto a Windows Service and set enabled=true...
              >>>>however, it does not appear to be firing. Do I need to do something
              >>>>else?
              >>>>
              >>>[/color]
              >>
              >> I have the same problem.
              >>
              >> Working in C++, my InitializeCompo nent() has
              >>
              >> this->ServiceTimer->Enabled = true;
              >> this->ServiceTimer->Interval = 1000;
              >> this->ServiceTimer->Tick += gcnew System::EventHa ndler(this,
              >> &EMuxServiceWin Service::Servic eTimer_Tick);
              >>
              >> My OnStart() has
              >>
              >> ServiceTimer->Start();
              >>
              >> and my OnStop() has
              >>
              >> ServiceTimer->Stop();
              >>
              >> My OnStart, OnStop, and ServiceTimer_Ti ck all have code to write to a
              >> log file. The OnStart and OnStart logs get written but the timer tick
              >> log never does.
              >>
              >> I confess to being a complete newbie at DotNet code, although I am
              >> rather experienced at MFC and Windows32 programming in general, so I
              >> might be missing something. But what could it be?
              >>
              >> Note: I have also tried putting the timer enable and interval set in
              >> OnStart.
              >>
              >>
              >>
              >>[/color]
              >
              >[/color]


              Comment

              • r norman

                #8
                Re: ServiceTimer won't fire

                On Fri, 28 Apr 2006 16:13:19 -0500, "SR" <sethricard@nor eply.com>
                wrote:

                Is top-posting the standard here? Strange!

                Thanks much for that information. It seems to be exactly what I (we)
                need. That was going to be my next try -- put the timers in the
                equivalent of a worker thread that does have the equivalent of a
                message pump! I'll bet my session-change detector will work inside a
                worker thread, also.

                [color=blue]
                >Try reading this article...
                >
                >http://www.codeguru.com/csharp/.net/...e.php/c6919__1
                >
                >"Thirsty Traveler" <nfr@nospam.com > wrote in message
                >news:ujUXWBvaG HA.4424@TK2MSFT NGP02.phx.gbl.. .[color=green]
                >> That is pretty much what I have done as well... but the thing won't start.
                >>
                >> "r norman" <NotMyRealEmail @_comcast.net> wrote in message
                >> news:fil452d4l9 h0vm3sfob1pfhbl 25khcvrsr@4ax.c om...[color=darkred]
                >>> On Fri, 28 Apr 2006 12:20:38 -0400, "Bob" <msgdev@hotmail .com> wrote:
                >>>
                >>>>You probably have to set the Interval value too.
                >>>>
                >>>>"Thirsty Traveler" <nfr@nospam.com > wrote in message
                >>>>news:%238BS kytaGHA.4580@TK 2MSFTNGP03.phx. gbl...
                >>>>>I dropped a Timer object onto a Windows Service and set enabled=true...
                >>>>>however, it does not appear to be firing. Do I need to do something
                >>>>>else?
                >>>>>
                >>>>
                >>>
                >>> I have the same problem.
                >>>
                >>> Working in C++, my InitializeCompo nent() has
                >>>
                >>> this->ServiceTimer->Enabled = true;
                >>> this->ServiceTimer->Interval = 1000;
                >>> this->ServiceTimer->Tick += gcnew System::EventHa ndler(this,
                >>> &EMuxServiceWin Service::Servic eTimer_Tick);
                >>>
                >>> My OnStart() has
                >>>
                >>> ServiceTimer->Start();
                >>>
                >>> and my OnStop() has
                >>>
                >>> ServiceTimer->Stop();
                >>>
                >>> My OnStart, OnStop, and ServiceTimer_Ti ck all have code to write to a
                >>> log file. The OnStart and OnStart logs get written but the timer tick
                >>> log never does.
                >>>
                >>> I confess to being a complete newbie at DotNet code, although I am
                >>> rather experienced at MFC and Windows32 programming in general, so I
                >>> might be missing something. But what could it be?
                >>>
                >>> Note: I have also tried putting the timer enable and interval set in
                >>> OnStart.
                >>>
                >>>
                >>>
                >>>[/color]
                >>
                >>[/color]
                >[/color]

                Comment

                • Thirsty Traveler

                  #9
                  Re: ServiceTimer won't fire

                  There appears to be a bug in the Timer component provided in the toolbox
                  when dropped onto a service. I deleted this and used the following, which
                  works.

                  using System.Threadin g;

                  {
                  public partial class MyService : ServiceBase
                  {

                  TimerCallback tcb = null;
                  Timer timer = null;

                  protected override void OnStart(string[] args)
                  {
                  tcb = new TimerCallback(t his.TimerCallba ck_Tick);
                  timer = new Timer(tcb, null, 0, 10000);
                  }

                  private void TimerCallback_T ick(object state)
                  {
                  //Do something
                  }
                  }



                  "r norman" <NotMyRealEmail @_comcast.net> wrote in message
                  news:7ns452lu5g ssrj6lof8h04dar 4vu08h993@4ax.c om...[color=blue]
                  > On Fri, 28 Apr 2006 11:19:02 -0700, "Thirsty Traveler"
                  > <nfr@nospam.com > wrote:
                  >[color=green]
                  >>"r norman" <NotMyRealEmail @_comcast.net> wrote in message
                  >>news:fil452d4 l9h0vm3sfob1pfh bl25khcvrsr@4ax .com...[color=darkred]
                  >>> On Fri, 28 Apr 2006 12:20:38 -0400, "Bob" <msgdev@hotmail .com> wrote:
                  >>>
                  >>>>You probably have to set the Interval value too.
                  >>>>
                  >>>>"Thirsty Traveler" <nfr@nospam.com > wrote in message
                  >>>>news:%238BS kytaGHA.4580@TK 2MSFTNGP03.phx. gbl...
                  >>>>>I dropped a Timer object onto a Windows Service and set enabled=true...
                  >>>>>however, it does not appear to be firing. Do I need to do something
                  >>>>>else?
                  >>>>>
                  >>>>
                  >>>
                  >>> I have the same problem.
                  >>>
                  >>> Working in C++, my InitializeCompo nent() has
                  >>>
                  >>> this->ServiceTimer->Enabled = true;
                  >>> this->ServiceTimer->Interval = 1000;
                  >>> this->ServiceTimer->Tick += gcnew System::EventHa ndler(this,
                  >>> &EMuxServiceWin Service::Servic eTimer_Tick);
                  >>>
                  >>> My OnStart() has
                  >>>
                  >>> ServiceTimer->Start();
                  >>>
                  >>> and my OnStop() has
                  >>>
                  >>> ServiceTimer->Stop();
                  >>>
                  >>> My OnStart, OnStop, and ServiceTimer_Ti ck all have code to write to a
                  >>> log file. The OnStart and OnStart logs get written but the timer tick
                  >>> log never does.
                  >>>
                  >>> I confess to being a complete newbie at DotNet code, although I am
                  >>> rather experienced at MFC and Windows32 programming in general, so I
                  >>> might be missing something. But what could it be?
                  >>>
                  >>> Note: I have also tried putting the timer enable and interval set in
                  >>> OnStart.
                  >>>[/color]
                  >>That is pretty much what I have done as well... but the thing won't start.[/color]
                  >
                  > I have taken the liberty of "correcting " your top-posting.
                  >
                  > Since I am new to DotNet I don't understand what is under the hood.
                  > But I was going to write my service in good old-fashioned Win32 code
                  > and, for that, I know that I need a window (albeit invisible for a
                  > service) and a message pump. My service also includes a SessionSwitch
                  > event processer which never gets signalled.
                  >
                  > Could it be that we have to add a MessageQueue or something like it to
                  > the service?
                  >
                  >[/color]


                  Comment

                  • r norman

                    #10
                    Re: ServiceTimer won't fire

                    On Fri, 28 Apr 2006 16:13:19 -0500, "SR" <sethricard@nor eply.com>
                    wrote:

                    Many thanks to both you and to Greg Young for suggesting a system
                    threading timer. I just avoided the whole thing by putting a
                    ServiceWorker in the service. It is trivial to put it into a sleep
                    loop to simulate a timer. Either the worker can implement the timer
                    tick function or it can signal to the main service through the
                    progress method. It is very simple and effective.
                    [color=blue]
                    >Try reading this article...
                    >
                    >http://www.codeguru.com/csharp/.net/...e.php/c6919__1
                    >
                    >"Thirsty Traveler" <nfr@nospam.com > wrote in message
                    >news:ujUXWBvaG HA.4424@TK2MSFT NGP02.phx.gbl.. .[color=green]
                    >> That is pretty much what I have done as well... but the thing won't start.
                    >>
                    >> "r norman" <NotMyRealEmail @_comcast.net> wrote in message
                    >> news:fil452d4l9 h0vm3sfob1pfhbl 25khcvrsr@4ax.c om...[color=darkred]
                    >>> On Fri, 28 Apr 2006 12:20:38 -0400, "Bob" <msgdev@hotmail .com> wrote:
                    >>>
                    >>>>You probably have to set the Interval value too.
                    >>>>
                    >>>>"Thirsty Traveler" <nfr@nospam.com > wrote in message
                    >>>>news:%238BS kytaGHA.4580@TK 2MSFTNGP03.phx. gbl...
                    >>>>>I dropped a Timer object onto a Windows Service and set enabled=true...
                    >>>>>however, it does not appear to be firing. Do I need to do something
                    >>>>>else?
                    >>>>>
                    >>>>
                    >>>
                    >>> I have the same problem.
                    >>>
                    >>> Working in C++, my InitializeCompo nent() has
                    >>>
                    >>> this->ServiceTimer->Enabled = true;
                    >>> this->ServiceTimer->Interval = 1000;
                    >>> this->ServiceTimer->Tick += gcnew System::EventHa ndler(this,
                    >>> &EMuxServiceWin Service::Servic eTimer_Tick);
                    >>>
                    >>> My OnStart() has
                    >>>
                    >>> ServiceTimer->Start();
                    >>>
                    >>> and my OnStop() has
                    >>>
                    >>> ServiceTimer->Stop();
                    >>>
                    >>> My OnStart, OnStop, and ServiceTimer_Ti ck all have code to write to a
                    >>> log file. The OnStart and OnStart logs get written but the timer tick
                    >>> log never does.
                    >>>
                    >>> I confess to being a complete newbie at DotNet code, although I am
                    >>> rather experienced at MFC and Windows32 programming in general, so I
                    >>> might be missing something. But what could it be?
                    >>>
                    >>> Note: I have also tried putting the timer enable and interval set in
                    >>> OnStart.
                    >>>
                    >>>
                    >>>
                    >>>[/color]
                    >>
                    >>[/color]
                    >[/color]

                    Comment

                    Working...