Minimizing to system tray causes stack overflow
-
Hi, I have a vewwy simple app which just sits in the system tray while doing its work. When a user double clicks the notification icon, a config window opens and you can edit some settings there. Right now, I have a simple form which will be hidden from the user and show a notification icon when formstate is set to minimized.
private void TrayForm\_Resize(object sender, EventArgs e) { if (FormWindowState.Minimized == this.WindowState) { notifyIcon1.Visible = true; this.Hide(); //this.ShowInTaskbar = false; } else if (FormWindowState.Normal == this.WindowState) { notifyIcon1.Visible = false; } }
For some reason, this works under windows xp, in windows7 I have to disable the ShowInTaskbar call, as that causes a stack overflow in the current thread. If I don't use the call, the form is minimized and remains visible on the taskbar, annoying at best. Any workarounds? (or am I doing something stupid here...?)
A good programmer is someone who always looks both ways before crossing a one-way street. (Doug Linder)
-
Hi, I have a vewwy simple app which just sits in the system tray while doing its work. When a user double clicks the notification icon, a config window opens and you can edit some settings there. Right now, I have a simple form which will be hidden from the user and show a notification icon when formstate is set to minimized.
private void TrayForm\_Resize(object sender, EventArgs e) { if (FormWindowState.Minimized == this.WindowState) { notifyIcon1.Visible = true; this.Hide(); //this.ShowInTaskbar = false; } else if (FormWindowState.Normal == this.WindowState) { notifyIcon1.Visible = false; } }
For some reason, this works under windows xp, in windows7 I have to disable the ShowInTaskbar call, as that causes a stack overflow in the current thread. If I don't use the call, the form is minimized and remains visible on the taskbar, annoying at best. Any workarounds? (or am I doing something stupid here...?)
A good programmer is someone who always looks both ways before crossing a one-way street. (Doug Linder)
Your statement is suggesting
this.ShowInTaskbar = false;
is firing the Resize event again. If that is so, you can break the loop by usingif (this.ShowInTaskbar) this.ShowInTaskbar = false; // avoid a Resize avalanche
. :) PS: Make sure to provide an appropriate comment to prevent someone from simplifying the code and reintroducing the problem.Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
Your statement is suggesting
this.ShowInTaskbar = false;
is firing the Resize event again. If that is so, you can break the loop by usingif (this.ShowInTaskbar) this.ShowInTaskbar = false; // avoid a Resize avalanche
. :) PS: Make sure to provide an appropriate comment to prevent someone from simplifying the code and reintroducing the problem.Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.