Preventing an exit

D

David Johnston

I've created some code (without using the form builder) that is extremely
simple. All it does is, in it's constructor, create a NotifyIcon and make it
visible. It also has a ContextMenu that quits the application.

The problem is, while the icon does display in the system tray when I run
the application, it disappears as soon as I put the mouse over it. On closer
inspection, the program just opens then closes immediately - the icon only
disappears when I make Windows update the tray by moving my mouse onto the
taskbar!

I want my app to stay open until I tell it to close.

I was advised to add a Thread that just yields in its loop, to block the
constructor from exiting, but isn't that a workaround? I want my app to lay
dormant until an event occurs (like the user hitting 'Quit' form the
contextmenu). Surely the framework has some method of achieving that?

Any advice hugely appreciated.

- Dave.
 
M

Michael Giagnocavo [MVP]

Can you show us your code? If your Main method is something like:

static public void Main() {
FormX die = new FormX()
die.Show();
}

Then it'll show, then return. You should use Application.Run(new FormX()).

-mike
MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top