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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:17:26+00:00 2026-06-09T15:17:26+00:00

I wrote extension method to Timer class to destroy it after certain amount of

  • 0

I wrote extension method to Timer class to destroy it after certain amount of time. seems like it actually only set false in timer.enable fields but don’t really set the whole things to false. Is there a way to nullify an object from it own extension method?

and another thing – is it good practice to implement it in that way or I should expect sync issues and more surprises?

timer.DestroyAfter(1.Hours()) :

     public static void DestroyAfter(this Timer timer, TimeSpan timeSpan)
      {
        var killingTimer = new Timer(timeSpan.TotalMilliseconds)
            {
                AutoReset = false,
            };

        killingTimer.Elapsed += (sender, e) =>
            {
                timer.Stop();
                **timer = null;** //doesn't seem to work though line is executed
                killingTimer.Stop();
                killingTimer = null;
            };
        killingTimer.Start();
    }
  • 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-09T15:17:28+00:00Added an answer on June 9, 2026 at 3:17 pm

    This would only be possible if the “this” parameter was also a ref parameter, which it is not.

    So the answer is no (in the current C# implementation)

    Regarding your other question: there’s nothing wrong with the way you implemented it (stopping the timer and clearing the reference to the captured “killingTimer” variable).

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

Sidebar

Related Questions

i have wrote a extension method for customize my validation messages, like this: namespace
I wrote a custom ordering LINQ extension method as below but I think it
I set up Open-xchage(wrote on Java) on openSUSE and installed SOAP extension on it.
I wrote this extension method (which compiles): public static IEnumerable<J> Flatten<T, J>(this IEnumerable<T> @this)
I wrote two extension methods to convert times from local time to UTC and
I wrote some extensions methods to handle the css class like how you would
I wrote the following extension method to get an element from a dictionary, or
I'd like to write an extension method for string, which appears as a static
I'm trying to write an extension method to insert data into a dictionary of
I'm trying to write an extension method for objects that will dump the structure

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.