Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

//This method allows users to display auto-disappearing messages using a BackGroundWorker (bgwStatus) and a ToolStripStatusLabel (tssLabel1)

private void showNotification(string message, Color color, int barValue)
{
	tssLabel1.ForeColor = color;
	tssLabel1.Text = message;
	tsPBar1.Value = barValue;
	if (bgwStatus.IsBusy)
		bgwStatus.CancelAsync();
	while (bgwStatus.IsBusy)
		Thread.Sleep(20);
	bgwStatus.RunWorkerAsync();
//Thread waitForNotification = new Thread(waitForNotificationOpportunity);
//waitForNotification.Start();
}


//In this Method the BackGround Worker Waits for about 2 seconds

private void bgwStatus_DoWork(object sender, DoWorkEventArgs e)
{
	for (int i = 0; i < 40; i++)
	{
		if (e.Cancel || bgwStatus.CancellationPending)
			return;
		Thread.Sleep(50);
	}
}


//Once the Time period (2 secs) has elapsed, the Label and the progress bar are reset.

private void bgwStatus_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
	tssLabel1.Text = "";
	tsPBar1.Value = 0;
}



I'd really appreciate the help. Thanks!!
Posted

1 solution

Hi,

have a look at the following codproject article:

TaskbarNotifier, a skinnable MSN Messenger-like popup in C# and now in VB.NET too[^]

best regards
 
Share this answer
 
Comments
Faizan S Kazi 19-Jun-10 14:26pm    
that looks really awesome!!! thank you!! :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900