473,505 Members | 16,800 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Persistant NotifyIcon with no window

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#....
Jul 21 '05 #1
1 1970
Never mind...I ate my Idiot-O's this morning...

Simply throw in an Application.Run() and everything works perfectly.

"Chris Melnick" wrote:
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#....

Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
3725
by: Hal Vaughan | last post by:
In the app I'm working on, there is a need, from all classes, to get configuration information. Much of that info is stored in single line files (which may be put in the Preferences structure in...
1
5657
by: Artur Kowalski | last post by:
I have a NotifyIcon in my Windows Service project and I am trying to add a ContextMenu to this NotifyIcon or use some of the mouse events. Everything isn't working. I think so base class of the...
1
1886
by: Claus Konrad | last post by:
Hi How would you "force" the ToolTip text to be displayed on a NotifyIcon? I want to inform the user that an action has happened in the "background", and would like to present this text using...
3
10971
by: Glen | last post by:
Can anyone tell me if there is a workable method to get the mouse cursor position on the screen or the NotifyIcon position? I need to display a context menu for the NotifyIcon when clicked and I'd...
1
409
by: Chris Melnick | last post by:
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...
1
7268
by: Marcel Brekelmans | last post by:
Hello, I have an application with a notifyIcon. When my application's main form is hidden by some other window I would like to bring it in front by single-clicking the NotifyIcon. However, I...
5
2881
by: celestialgal86 | last post by:
Hi everyone... I'm a starter at .Net programming, and I need some help. I was asked to develop a console app that will auto-hide the console window and show a system tray icon. And by...
0
969
by: Mrozu | last post by:
Hi, VB.NET 2003 I'v got NotifyIcon, on minimize button click, my app is hiding to tray by following code: ni.Visible = True Me.Hide() Me.WindowState = FormWindowState.Minimized
1
4275
by: \Ji Zhou [MSFT]\ | last post by:
Hello Jason, Thanks for using Microsoft Newsgroup Support Service, my name is Ji Zhou and I will be working on this issue with you. I have tried to but cannot reproduce your issue on my side....
0
7218
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7307
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7478
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5035
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1532
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
409
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.