473,511 Members | 14,825 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# Prevent multiple delayed NofityIcon BalloonTips overflow.

Tyler Wiebe
66 New Member
I've come across a slight problem that I'm not sure how to fix.

First I'll let you know that this is mainly because of one of my applications that has a notify icon, and it's connected to my iTunes, and when ever iTunes changes songs, my application gets notified, and then shows a balloon tip about the current song playing in iTunes.

The problem is, if I step away from my computer, and another notify icon other than mine has a balloon tip, mine won't appear until my computer gets some sort of user input.
This is fine... Unless I leave iTunes running for who knows how long.

Let's say a balloon tip appears that isn't mine, and my application gets notified that iTunes has changed songs 100 times by the time that my computer gets user input again, this causes the balloon tip that isn't mine to disappear, and then mine to appear... But the first one, and then that one will disappear, and then it'll show the second one, and then disappear as well, and this keeps going until it reaches the current balloon tip that it should be showing, or the song changes again.

Now I'm assuming the problem lies in how windows handles balloon tips, because awhile ago I read something about balloon tips and how they work, and from what I remember, this is something to do with that.

Anyway, if someone could suggest a way or tell me how to prevent multiple delayed balloon tips, that would be great...
And if I'm out of luck, please let me know as well.
Jul 7 '12 #1
1 4483
Tyler Wiebe
66 New Member
Well I think I've found a temporary solution to my problem.

Expand|Select|Wrap|Line Numbers
  1.     public partial class Form1 : System.Windows.Forms.Form
  2.     {
  3.         public System.Windows.Forms.NotifyIcon MyIcon { get; set; }
  4.         public System.Windows.Forms.NotifyIcon OtherIcon { get; set; }
  5.         public bool BalloonWaiting { get; set; }
  6.  
  7.         public bool UseDefaultMethod { get; set; }
  8.  
  9.         public Form1()
  10.         {
  11.             InitializeComponent();
  12.  
  13.             this.UseDefaultMethod = true;
  14.  
  15.             this.OtherIcon = new System.Windows.Forms.NotifyIcon();
  16.             this.OtherIcon.Icon = this.Icon;
  17.             this.OtherIcon.Visible = true;
  18.  
  19.             this.MyIcon = new System.Windows.Forms.NotifyIcon();
  20.             this.MyIcon.Icon = this.Icon;
  21.             this.MyIcon.BalloonTipShown += new System.EventHandler(NotifyIcon_BalloonTipShown);
  22.             this.MyIcon.Visible = true;
  23.         }
  24.  
  25.         public void NotifyIcon_BalloonTipShown(object sender, System.EventArgs e)
  26.         {
  27.             this.BalloonWaiting = false;
  28.         }
  29.  
  30.         public void ShowBalloon(int Timeout, string Title, string Text, System.Windows.Forms.ToolTipIcon Icon)
  31.         {
  32.             if (string.IsNullOrEmpty(Title)) Title = " ";
  33.             if (string.IsNullOrEmpty(Text)) Text = " ";
  34.  
  35.             this.MyIcon.BalloonTipTitle = Title;
  36.             this.MyIcon.BalloonTipText = Text;
  37.             this.MyIcon.BalloonTipIcon = Icon;
  38.  
  39.             if (this.MyIcon.Visible)
  40.             {
  41.                 System.Console.WriteLine(this.BalloonWaiting);
  42.                 if (!this.BalloonWaiting)
  43.                 {
  44.                     this.BalloonWaiting = true;
  45.                     this.MyIcon.ShowBalloonTip(Timeout);
  46.                 }
  47.                 else
  48.                 {
  49.                     this.MyIcon.Visible = false;
  50.                     this.MyIcon.Visible = true;
  51.  
  52.                     this.MyIcon.ShowBalloonTip(3000);
  53.                 }
  54.             }
  55.         }
  56.  
  57.         private void Form1_Click(object sender, System.EventArgs e)
  58.         {
  59.             this.OtherIcon.ShowBalloonTip(10000, "Blocking Application", "I'm blocking you.", System.Windows.Forms.ToolTipIcon.Info);
  60.  
  61.             if (this.UseDefaultMethod)
  62.             {
  63.                 this.MyIcon.ShowBalloonTip(3000, "Bob", "Says hello.", System.Windows.Forms.ToolTipIcon.Info);
  64.                 System.Threading.Thread.Sleep(3000);
  65.                 this.MyIcon.ShowBalloonTip(3000, "Bob", "Says hello again.", System.Windows.Forms.ToolTipIcon.Info);
  66.                 System.Threading.Thread.Sleep(3000);
  67.                 this.MyIcon.ShowBalloonTip(3000, "Bob", "Says hello once again.", System.Windows.Forms.ToolTipIcon.Info);
  68.                 System.Threading.Thread.Sleep(3000);
  69.                 this.MyIcon.ShowBalloonTip(3000, "Why", "Is bob saying hello so much.", System.Windows.Forms.ToolTipIcon.Info);
  70.             }
  71.             else
  72.             {
  73.                 this.ShowBalloon(3000, "Bob", "Says hello.", System.Windows.Forms.ToolTipIcon.Info);
  74.                 System.Threading.Thread.Sleep(3000);
  75.                 this.ShowBalloon(3000, "Bob", "Says hello again.", System.Windows.Forms.ToolTipIcon.Info);
  76.                 System.Threading.Thread.Sleep(3000);
  77.                 this.ShowBalloon(3000, "Bob", "Says hello once again.", System.Windows.Forms.ToolTipIcon.Info);
  78.                 System.Threading.Thread.Sleep(3000);
  79.                 this.ShowBalloon(3000, "Why", "Is bob saying hello so much.", System.Windows.Forms.ToolTipIcon.Info);
  80.             }
  81.         }
  82.  
The only problem with this is that there is a flicker in the system tray every so often when the icon visibility is toggled.

Any improvements are welcome, and any better solutions are really welcome.
Jul 7 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2668
by: Job Lot | last post by:
How can I prevent multiple instances of MdiChild form? I have a MdiParent form with a DataGrid showing all the clients in the database. User clicks on a row to open MdiChild form which display...
4
12230
by: logicalfeline | last post by:
How do you prevent multiple instances of a program from running? Cat
2
6310
by: Brian Keating EI9FXB | last post by:
Hello there, What is the best way in c# to prevent multiple instances of my application running at same time on one machine? thanks Brian
6
4365
by: anoj | last post by:
Hi All i need to prevent multiple logins from the same user at the same time. what is the best way to do this . How can i detect if a user closes the browser window without logging out so tht...
18
3364
by: Gleep | last post by:
I've searched google intensely on this topic and it seems noone really knows how to approch this. The goal I don't want clients to give out their usernames and passwords to friends, since the site...
1
1804
by: lushgrass | last post by:
this is a .net 2003 c# windows form project. there is a menu button called "search" it does a lot of stuff and takes some time. i need to prevent the form from allowing the user to click on it...
3
1907
by: Aliriazi | last post by:
All, I have created a simple database, which includes a receiving table and outgoing table in my receiving table I have a multiple entry of the same fields. I am trying to create a query that...
6
6193
by: Bhavini | last post by:
Hi All, I have to prevent multiple logins for the same user accessing at same time. i.e. if xyz user is active, no other login should be allowed for the same user ID. I thought of saving...
2
2462
by: Job Lot | last post by:
How can I prevent multiple instances of a C# windows forms application. VB.NET provides My.Application.StartupNextInstance Event to do this. Is there any C# equivalent as well? Thanks
4
10996
by: visweswaran2830 | last post by:
Hi, I want to prevent multiple user login for same user in asp.net.. How can I achieve. Note: I want to control without database concepts
0
7252
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
7371
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
7517
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...
1
5077
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
4743
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...
0
3230
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
1583
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 ...
1
791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
452
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.