Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Minimizing to system tray causes stack overflow

Minimizing to system tray causes stack overflow

Scheduled Pinned Locked Moved C#
data-structuresquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Helfdane
    wrote on last edited by
    #1

    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)

    L 1 Reply Last reply
    0
    • H Helfdane

      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)

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Your statement is suggesting this.ShowInTaskbar = false; is firing the Resize event again. If that is so, you can break the loop by using if (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.

      H 1 Reply Last reply
      0
      • L Luc Pattyn

        Your statement is suggesting this.ShowInTaskbar = false; is firing the Resize event again. If that is so, you can break the loop by using if (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.

        H Offline
        H Offline
        Helfdane
        wrote on last edited by
        #3

        Thanx for the tip, will try it out soonish as my harddrive died on me today X|

        A good programmer is someone who always looks both ways before crossing a one-way street. (Doug Linder)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups