title: Custom control and dispose
body: <p>The start of story is <a href="https://stackoverflow.com/questions/20067353/destroying-the-form">here</a>.</p>
  
  <p>I have a component and I want it to <em>clean</em> up timers (managed resources, right?):</p>
  
  <pre><code>public class MyPictureBox : PictureBox, IDisposable
  {
      private Timer _timer1 = new Timer();
      private Timer _timer2 = new Timer();
      public MyPictureBox(): base()
      {
          _timer1.Interval = 100;
          _timer1.Start();
          _timer2.Interval = 250;
          _timer2.Start();
      }
  
      // ... all sort of code
  
  
      new void Dispose()
      {
          base.Dispose();
          _timer1.Dispose();
          _timer2.Dispose();
      }
  
      void IDisposable.Dispose()
      {
          _timer1.Dispose();
          _timer2.Dispose();
      }
  }
  </code></pre>
  
  <p>As you can see, I tried to implement one more (oO) <code>IdDisposable</code> (despite PictureBox->Control->Component->IDisposable). But.. none of them is called.</p>
  
  <p>Control is put on form by using designer. But it is doesn't appears in form <code>Components</code> and this should be the reason why it is not called when form is disposed:</p>
  
  <pre><code>Form1 form = new Form1();
  form.Dispose(); // MyPictureBox.Dispose() are not called
  </code></pre>
  
  <p>My question is how should I organize disposing of my control timers to have what I needed - disposing of MyPictureBox timers together with form disposing?</p>