You do not have a timer after use. This is what delays its collection.
If your class contains objects that implement IDisposable (e.g. Timer ), it must also implement IDisposable .
public class TestTimer : IDisposable { private Timer timer; public TestTimer() { timer = new Timer(1000); ... } #region IDisposable public void Dispose() { Dispose(true); } volatile bool disposed = false; protected virtual void Dispose(bool disposing) { if (disposing && !disposed) { timer.Dispose(); GC.SupressFinalize(this); disposed = true; } } ~TestTimer() { Dispose(false); } #endregion }
Your main method should look like this:
public static void Main() { using (TestTimer timer = new TestTimer()) {
Again, if your TestTimer needs to live longer than the scope of one Main method, then the class that creates it and contains the link must also implement IDisposable .
source share