0

I have below line of code in my Windows application.

Below is the code which get trigger on click of tray icon click, and NotifyForm is normal Windows form.

            ExceptionManager.Process(
            () =>
            {
                if (notifyForm == null)
                {
                    notifyForm = new NotifyForm();
                    notifyForm.Deactivate += (o, args) =>
                    {
                        notifyForm.Close();
                    };

                    notifyForm.Disposed += (o, args) =>
                    {
                        notifyForm = null;
                    };
                }

                if (!notifyForm.Visible)
                {
                    notifyForm.ShowPopup();
                }
                else
                {
                    notifyForm.Close();
                }

            }, "Policy");

Form is closing fine, when I run it through Visual Studio, if I navigate to Release folder and run exe explicitly, Deactivate event never fires. Help on this really appreciated.

Just for more information, notifyForm is notification pop up window which shows up above the tray, on click of tray icon.

Also, I have tried running application in release mode through visual studio, and it works fine. Only problem start happening when i run it outside of studio.

I have verified exe is up to date.

Edit - Basically I have form which i open on click of tray icon, and expecting clicking on desktop or some where should trigger deactivate event, which is not happening. Not sure why. :(

Rahul K
  • 17
  • 1
  • 9

3 Answers3

1

You need to compile your code in release to update the .exe!

EDIT: Maybe this link can help you

J. Lavoie
  • 335
  • 2
  • 5
  • 23
  • He's seen a few things. Guaranteed he's got the 200 yard look. – Fletchius Jun 20 '17 at 19:28
  • "Also, I have tried running application in release mode through visual studio, and it works fine. Only problem start happening when i run it outside of studio. I have verified exe is up to date." The OP is explicitly running in Release Mode which, for that, **it's already compiled as Release**. Not sure why anyone upvoted this useless answer – Camilo Terevinto Jun 20 '17 at 19:32
  • @CamiloTerevinto I've commented before he updated his question ahah – J. Lavoie Jun 20 '17 at 19:33
  • Thanks J. Lavoie, link is talking about notify icon hover / close. I am looking for behavior where if i click on deskstop or anywhere, form should get closed. – Rahul K Jun 20 '17 at 19:42
  • @RahulK Check JoePhilips comment on your post so we can help you! – J. Lavoie Jun 20 '17 at 20:01
  • Thanks JoePhilips. However that won't help. Bascally i have form which i open on click of tray icon, and expecting clicking on desktop or some where should trigger deactivate event, which is not happening. Not sure why. :( – Rahul K Jun 21 '17 at 01:36
0

Thanks all for your help.

Calling below method, after showing pop up solved my issue.

notifyForm.Activate();

Thanks again.

Rahul K
  • 17
  • 1
  • 9
-1

Because VS runs code in a nice debug environment. Even in release mode. It keeps references alive longer than when running outside of the debugger.

Store notifyForm in a scope that will be alive at the time deactivate might be called. Easiest is a class variable.

K Smith
  • 60
  • 5