473,383 Members | 1,978 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,383 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 4312
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...

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.