Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7858033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:14:17+00:00 2026-06-02T21:14:17+00:00

I building a service application in c#. i’m trying to make my action (array)

  • 0

I building a service application in c#. i’m trying to make my action (array) with timer every 2 second. but my timer keep die after my function call finished.

my Onstart:

   ...
   Alaram  Fi = new Alaram();
   Fi.AgentStart();
   GC.KeepAlive(Fi);
   ...

My Alaram class:

    public void AgentStart()
    {
        ...
        int i = 0;
        Timer[] timers = new Timer[count];

        while (myReader.Read())
        {
            timers[i] = new Timer(coba, myReader["DeviceId"], 0, 2000);
            i++;
        }
        GC.KeepAlive(timers);

     }

My Action:

 public void coba(object id)
 {
        ...

        int sec = Convert.ToInt32((string)myCommand.ExecuteScalar());
        sec++;

        myCommand = new SqlCommand("UPDATE Roles  SET  Value ='" + sec.ToString() + "' WHERE   Name = 'Fire" + id.ToString() + "'", ibmsConnect);
        myCommand.ExecuteNonQuery();
        ...
  }

my timer only execute maximum 36 times after that my timer didn’t execute anymore. I need it to keep live until the service is stop

anyone have idea why my timer keep stoping tick??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T21:14:20+00:00Added an answer on June 2, 2026 at 9:14 pm

    GC.KeepAlive will only prevent aggressive garbage collecting on the timers for the scope in which they are declared (or stored), which would be the array in the AgentStart method. Once the array and the timers go out of scope (when the method is done executing) they will begin to be collected by garbage collection.

    You will need to declare the array in a location where it will stay in scope. One way to do this is by marking the array as static and placing it on the class level . Next instantiate the timers you assign to the array in a static constructor of the class. This should keep them alive.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building Flex 3 application and I have a geocoding service ( http://.../GeocodeServer )
Building a new ASP.net application, and planning to separate DB, 'service' tier and Web/UI
I am building a web/mobile social service application for Windows Phone. As a final
When building a WCF service for a large scale application, which is better: In
An application I'm building uses a local Service for downloading files from the web
I'm thinking about building an application with a RESTful web service. My thought is
I'm building an application with a Silverlight frontend that communicates with a backend service
I'm building a windows service application which has a configuration to compile it as
I'm building a multi-threaded service application in Delphi XE2. Each thread serves its own
I'm building a multi-threaded windows service application in Delphi XE2 which uses ADO database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.