G
Guest
I am trying to write an application that runs in the system tray, so I am
using a NotifyIcon not associated with a Form. My "main" class has an
instance of the NotifyIcon, and its ContextMenu, as well as other dialogs etc
that are accessed through the ContextMenu.
However, since there is no window open, the main thread completes after
initializing everything and the application exits. I tried to add a keep
alive thread that runs until you select "Exit" from the ContextMenu. I have
no idea why, but adding that thread screws up the ContextMenu. When you
select an item from the menu, it won't perform the event until you click on
the NotifyIcon again. Very strange. This only happens when I have the keep
alive thread running (the keep alive thread simply is while(threadShouldRun)
{ Thread.sleep(500); }, threadShouldRun is set when you select "Exit".
Is there a better way to keep the NotifyIcon persistant? I also tried a
workaround of adding an empty form with the opacity = 0, and ShowDialog() on
it. That works fine, but seems like a very poor way to accomplish what I am
trying to do.
Any ideas? I am using C#....
using a NotifyIcon not associated with a Form. My "main" class has an
instance of the NotifyIcon, and its ContextMenu, as well as other dialogs etc
that are accessed through the ContextMenu.
However, since there is no window open, the main thread completes after
initializing everything and the application exits. I tried to add a keep
alive thread that runs until you select "Exit" from the ContextMenu. I have
no idea why, but adding that thread screws up the ContextMenu. When you
select an item from the menu, it won't perform the event until you click on
the NotifyIcon again. Very strange. This only happens when I have the keep
alive thread running (the keep alive thread simply is while(threadShouldRun)
{ Thread.sleep(500); }, threadShouldRun is set when you select "Exit".
Is there a better way to keep the NotifyIcon persistant? I also tried a
workaround of adding an empty form with the opacity = 0, and ShowDialog() on
it. That works fine, but seems like a very poor way to accomplish what I am
trying to do.
Any ideas? I am using C#....