Hi Joe,
Thank you for using Microsoft Managed Newsgroup Service, I'm Zhi-Xin Ye,
it's my pleasure to work with you on this issue.
As I understand, you want to display a waiting message while the UI thread
is busying computing. However, it's not recommend to execute time-consuming
operations in the UI thread, as it will freeze the UI.
The recommended way is to use the BackgroundWorker component, you can
iterate through your data in the BackgroundWorker.DoWork event, and call
the BackgroundWorker.ReportProgress() method to report and send data to the
UI whenever neccessary. Once the BackgroundWorker.ReportProgress() method
is called, the BackgroundWorker.ProgressChanged event fires, then you can
update your UI (e.g. using the data passed from ReportProgress() method to
paint the chart) in the ProgressChanged event handler. Meanwhile, you can
display a label or a ProgressBar to show the progress.
A sample for your information:
public partial class Form1 : Form
{
BackgroundWorker worker;
public Form1()
{
InitializeComponent();
worker = new BackgroundWorker();
worker.DoWork += new DoWorkEventHandler(worker_DoWork);
worker.ProgressChanged += new
ProgressChangedEventHandler(worker_ProgressChanged);
worker.RunWorkerCompleted += new
RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
//By default the progress reporting is disabled, we have to
enable it.
worker.WorkerReportsProgress = true;
}
void worker_DoWork(object sender, DoWorkEventArgs e)
{
// do you data loading here,
// whenever you want to update the UI, call the ReportProgress
method
// and transfer the data you want need.
worker.ReportProgress(10, dataNeededInUI);
}
void worker_RunWorkerCompleted(object sender,
RunWorkerCompletedEventArgs e)
{
this.Label1.Text = "Complete!";
}
void worker_ProgressChanged(object sender, ProgressChangedEventArgs
e)
{
// This event fires whenever you call theReportProgress method
// Update the UI here with the data sent from the
BackgroundWorker here.
//Display the progress
this.Label1.Text = "Please waiting....";
}
private void button1_Click(object sender, EventArgs e)
{
if (!worker.IsBusy)
worker.RunWorkerAsync();
}
}
For more information about the BackgroundWorker, you can refer to this
document:
BackgroundWorker Class
http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundwork
er.aspx
If anything is unclear or you have any concerns, please feel free to let me
know, I will be happy of assistance.
Have a nice day!
Best Regards,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.