473,401 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

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 1965
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
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
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
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
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
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
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
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
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
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...
0
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...

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.