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 114627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:53:27+00:00 2026-05-11T02:53:27+00:00

The documentation of System.Threading.Timer says that I should keep a live reference for it

  • 0

The documentation of System.Threading.Timer says that I should keep a live reference for it to avoid it being garbage collected. But where should I do that? My main is very simple that I don’t know where to keep the reference:

class Program {     static void Main() {         new System.Threading.Thread(myThreadStart).Start();         new System.Threading.Timer(myTimerCallback, new MyStateObject(), 0, 5000);     } } 

I thought about keeping the reference in a static field in the Program class, assuming that static fields do not get collected until the end of the application. But I’m not sure this is the best way to do it, so I’d appreciate your advice.

  • 1 1 Answer
  • 3 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. 2026-05-11T02:53:28+00:00Added an answer on May 11, 2026 at 2:53 am

    If your Timer is an application-level object there’s nothing wrong with making it a private static member of your Main class. That’s what I would do, anyway.

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

Sidebar

Related Questions

The documentation for +[NSThread detachNewThreadSelector:toTarget:withObject:] says: For non garbage-collected applications, the method aSelector is
The System.Threading.ConcurrentQueue.TryDequeue method threw an exception the other day that took me totally by
I'm writing an app that will need to make use of Timer s, but
Is there a C/C++ library, and documentation about how to collect system and process
Documentation can be found here It says in the example: onDrop: Called whenever a
Documentation simply states that setting setAutosavingDelay to anything > 0 on the shared doc
The documentation for the round() function states that you pass it a number, and
The documentation indicates that the error: option function will make available: XHR instance, a
According to the documentation the maximum dueTime value is 4294967294 milliseconds. But if you
The documentation states that: The Q_OBJECT macro must appear in the private section of

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.