c# application, Handles in task manager increase and system hanged
<p>In our application we used Threads and Delegate to get the best performance.  In order to gate our operations we use the <code>System.Timers.Timer</code> class.
When the application start , after 1 hour the task manager shows that the number of handles increased and cpu usage increases as well.</p>

<p>What can we do to dispose objects of Thread and delegate?</p>

<p>below code can help you to check this task.</p>

<pre><code>public partial class Form1 : Form
{
    System.Timers.Timer MainTimer;
    public Form1()
    {
        InitializeComponent();
        MainTimer = new System.Timers.Timer();
        MainTimer.Elapsed+=new System.Timers.ElapsedEventHandler(MainTimer_Elapsed);

    }
    Thread MainThread;
    private void button1_Click(object sender, EventArgs e)
    {
        MainTimer.Interval = 10;
        MainTimer.Start();
    }

    void MainTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {
        MainThread = new Thread(new ThreadStart(DoStart));
        MainThread.Start();
    }
    void DoStart()
    {
        PrintInfo();
    }
    delegate void PrintInfo_Delegate();
    void PrintInfo()
    {
        if (textBox1.InvokeRequired)
        {
            Invoke(new PrintInfo_Delegate(PrintInfo));
        }
        else
        {
            textBox1.Text += "Test\r\n";
        }
    }
}
</code></pre>
