473,657 Members | 2,523 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(threadSho uldRun)
{ Thread.sleep(50 0); }, 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 1980
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(threadSho uldRun)
{ Thread.sleep(50 0); }, 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
3742
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 java.util.prefs later). I've experimented with different ways to access these modes. Part of the problem is that I have to be sure the "home" mode is set so the Config class can always read the config directory (and the files in it) from within...
1
5682
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 service System.ServiceProcess.ServiceBase don't catchWindows messages like mouse or timer messages. Any Idea? Thanks,
1
1893
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 the taskbar control (NotifyIcon). It is not possible to inherit from System.Windows.Forms.NotifyIcon and thereby creating an event to do this stuff, and there is no native event called "MouseOver" or something like that...
3
10982
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 like it to display based on the relative position of the tray icon or mouse pointer if possible (whichever method works). Any help would be much appreciated. - Glen
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 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...
1
7292
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 can't get it done. In the Click event I've used all sorts of methods: this.SetTopLevel(true); this.Show(); this.Focus();
5
2901
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 default, the system tray icon on click is supposed to show the console window I know window apps are usually the better solution for handling NotifyIcon class, but I would really like to know how to do it in console apps
0
983
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
4288
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. From your codes, I think the logical is, every time the Timer's elapsed event fires, we call the Check_For_Version_Update() function. From the Check_For_Version_Update() function, we judge a condition statement, and determine whether to call...
0
8403
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8316
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8833
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8509
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5636
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4327
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2735
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 we have to send another system
2
1967
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1730
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.