我有一个WinForm C#应用程序,我正在编程生成一个pdf文件并通过电子邮件发送它。我试图显示状态标签,显示状态(生成文件,发送,发送成功或失败)。但它只显示最后的状态(发送成功)。 我应该怎么做来显示状态更新?正在更新状态标签C#
我试过下面的代码。
try
{
Status_Label.Invoke((MethodInvoker)(() => Status_Label.Text ="Generating PDF fie..."));
/*
GENERATING CODE TO CREATE PDF FILE
*/
Status_Label.Invoke((MethodInvoker)(() => Status_Label.Text = "Sending Email..."));
/*
GENERATING CODE for sending the Email
*/
Status_Label.Invoke((MethodInvoker)(() => Status_Label.Text = "Sent successfully."));
}
catch (Exception ex)
{
Status_Label.Invoke((MethodInvoker)(() => Status_Label.Text = "Sending failed."));
}
您是否检查过此页面右侧“相关”部分下的任何链接..这听起来像是一个好起点http://stackoverflow.com/questions/13152075/multithreading-in- c-sharp-update-labels?rq = 1 – MethodMan
使用'BackgroundWorker'。看起来你正在运行GUI线程中提到的代码。 – imlokesh