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();
}
//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!!