The only correct way to place disposable members of the IDisposable class is to make it inside your Dispose(bool disposing) method (check the MSDN article). In other words, you can open the autogenerated file Form.Designer.cs and put it in the correct method.
On the other hand, if you add Timer via VS Designer (instead of creating it yourself), it will be added to the components container:
// autogenerated inside Form.Designer.cs, InitializeComponent() method this.timer = new System.Windows.Forms.Timer(this.components);
and then correctly positioned when the components element is positioned:
// autogenerated inside Form.Designer.cs, Dispose(bool disposing) method if (disposing && (components != null)) { components.Dispose(); }
If you want to do this yourself, keep in mind that the designer does not create an instance of components if he does not consider it necessary. Thus, components can be null in your case.
The easiest way to solve this problem is to add a timer by dragging it from the toolbar, then run it inside the Form_Load handler.
source share