473,406 Members | 2,707 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,406 software developers and data experts.

Win Forms - Display self Disappearing Notifications/PopUps in quick succession?

Hi all!
I really need to show neat and professional looking messages, like helper tips, or error notifications, in quick succession, often occurring before the first message has disappeared....

I was trying to display those notifications in a ToolStripStatusLabel, but whats happening with my code is I have to wait for my background worker to finish displaying one message, before the other can be displayed and this hangs the UI thread, completely crashing the program.

Expand|Select|Wrap|Line Numbers
  1. //This method allows users to display auto-disappearing messages using a BackGroundWorker (bgwStatus) and a ToolStripStatusLabel (tssLabel1)
  2.  private void showNotification(string message, Color color, int barValue)
  3.         {
  4.             tssLabel1.ForeColor = color;
  5.             tssLabel1.Text = message;
  6.             tsPBar1.Value = barValue;
  7.             if (bgwStatus.IsBusy)
  8.                 bgwStatus.CancelAsync();
  9.             while (bgwStatus.IsBusy)
  10.                 Thread.Sleep(20);
  11.             bgwStatus.RunWorkerAsync();
  12.             //Thread waitForNotification = new Thread(waitForNotificationOpportunity);
  13.             //waitForNotification.Start();
  14.         }
  15.  
  16. //In this Method the BackGround Worker Waits for about 2 seconds
  17. private void bgwStatus_DoWork(object sender, DoWorkEventArgs e)
  18.         {
  19.             for (int i = 0; i < 40; i++)
  20.             {
  21.                 if (e.Cancel || bgwStatus.CancellationPending)
  22.                     return;
  23.                 Thread.Sleep(50);
  24.             }
  25.         }
  26.  
  27. //Once the Time period (2 secs) has elapsed, the Label and the progress bar are reset.
  28.         private void bgwStatus_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
  29.         {
  30.             tssLabel1.Text = "";
  31.             tsPBar1.Value = 0;
  32.         }
  33.  
I'd really appreciate the help. Thanks!!
Jun 18 '10 #1

✓ answered by GaryTexmo

A couple of things...

1) Try a message queue. Instead of having your GUI thread wait to show the next message, create a new class to hold messages in a queue with a timer. Whenever the timer ticks, it changes the message. You can still do this with a background worker, just have the timer govern the showing of messages and managing the queue.

2) You might want to look into a NotifyIcon's ShowBalloonTip method for this... maybe that will help with your presentation?

4 4313
GaryTexmo
1,501 Expert 1GB
A couple of things...

1) Try a message queue. Instead of having your GUI thread wait to show the next message, create a new class to hold messages in a queue with a timer. Whenever the timer ticks, it changes the message. You can still do this with a background worker, just have the timer govern the showing of messages and managing the queue.

2) You might want to look into a NotifyIcon's ShowBalloonTip method for this... maybe that will help with your presentation?
Jun 19 '10 #2
Thanks Gary!

1)I thought about a message queue, I was just worried about messages piling up and not being written in good time...

like if a user selects 4 different rows from a grid view in quick succession, and i'm taking 2 seconds to display each message about the gridrow selected, it'll take 8 seconds to display all the messages, the user might be confused when he gets backed up messages that dont relate to the most recent click. :s but it is a good solution, even if its not the sleekest.

2) I shall check out NotifyIcon's ShowBalloonTip method, i'm just worried its a little more graphics intensive and windows 7 now hides notifications, so either the user will miss notifications or the computer might get bogged down if too many messages are piling up.

Thanks so much for your help! i'll check out both solutions and get back to you about which seems more efficient. also, for any wanderers who look up this post. :)
Jun 19 '10 #3
@GaryTexmo
So i tried the message queue! it worked well!! :)

I made a custom class storing the (string) message, (Color) color of the message and (int) progress bar value.

I made a Queue for my custom class and using a timer, I kept picking notifications off the Queue if there were any, otherwise setting my controls to their default values :)

thanks so much for your help! :D
Jun 19 '10 #4
GaryTexmo
1,501 Expert 1GB
You're quite welcome, glad it worked out for you :)
Jun 20 '10 #5

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

Similar topics

2
by: Daniel Nouri | last post by:
The idea of my simple piece of code is to start from a given module and wrap all functions and methods in that module and submodules. FunWrapper is the class that I use for wrapping. The last...
52
by: Harlan Messinger | last post by:
Can you help me figure out what to do about popups? Sometimes we develop web applications where popups make very good sense for precisely the same reasons they make sense in traditional...
5
by: Arthur T. Murray | last post by:
http://www.scn.org/~mentifex/jsaimind.html is a free, public-domain AI in JavaScript that may be copied to your Web site with your own changes. Freshly updated and modified from the AI Mind-1.1...
2
by: Brad Quinn | last post by:
It appears that IIS hangs the first time two requests are made for same page in quick succession. Although it may very well be something else I'm doing wrong. I have a page (ViewDocument.aspx)...
5
by: Jensen Bredal | last post by:
Hello, I need to display self refreshing information on a web page written with asp.net. I would image that the info would be displayed either as part of a user control or a web control. How can...
2
by: bjhess | last post by:
I am working on an application that includes a screen with a list of people on the right and a list of groups they can be involved in on the left. The user can drag-and-drop people from the right...
1
by: YotamElal | last post by:
Hello, I have a popup problem. When a popup is opened, I want all other popups to close immediatly. (except for its self and it's child popups) Here is my code: code: <!DOCTYPE HTML PUBLIC...
9
by: tomhawkins1 | last post by:
Hi I currently have a site where users can upload files. These files can be doc, wmv, jpeg, xls, dwf, dwf and dwg. These files are uploaded to /home/**user**/uploads and not /home/...
5
by: njuneardave | last post by:
I have a full-screen C# app, but windows notifications (the little balloons on the bottom right-hand of the screen) and outlook reminders will pop on top of my app. i want to prevent them from...
3
by: =?Utf-8?B?QmlsbHkgWmhhbmc=?= | last post by:
I have a asp.net app, in the page there is a scan activex which could scan and save a jpg file in client harddisk. How could we access and display this jpg file on the fly using js in the client...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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
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
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.