title: c# program crashes/closes on minimize to system tray
body: <p>I write on a little tool that should watch my server an write me mails when something went wrong like too high ram usage etc...</p>
  
  <p>now to my problem, I want to minimize my Program to system tray and it works fine :) I see for some seconds the icon in the tray. after that my program is gone...closed...dont know process is away :D.</p>
  
  <p>Here my code to minimize to tray:</p>
  
  <pre><code>InitializeComponent();
  var icon = new NotifyIcon();
  icon.Icon = new Icon("watchdog.ico");
  icon.Visible = true;
  icon.DoubleClick +=
         delegate(object sender, EventArgs args)
         {
             this.Show();
             this.WindowState = WindowState.Normal;
         };
  
  protected override void OnStateChanged(EventArgs e)
         {
             if (WindowState == WindowState.Minimized)
                  this.Hide();
  
             base.OnStateChanged(e);
         }
  </code></pre>
  
  <p>I hope u can help me.</p>