【发布时间】:2014-01-11 22:56:47
【问题描述】:
我有这个长时间运行的进程,我想在主应用程序表单上显示一个表单,说明它使用无处不在的圆形进度条长时间运行。我只是无法让任何东西正常工作。表单没有正确显示或动画进度圈。如果我尝试如图所示的不同方法,则任务不会完成!
private void lbMethods_SelectedIndexChanged(object sender, EventArgs e)
{
switch (lbMethods.SelectedIndex)
{
case (int)Methods.none:
break;
case (int)Methods.Susan:
Log("Starting Susan Edge Detection");
Progressing("Please wait for edge detection");
Task t = new Task(() => ProcessSusan());
while (!t.IsCompleted)
{
Application.DoEvents();
}
Log("Detection Finished");
Progressing("", false);
break;
default:
break;
}
}
private void ProcessSusan()
{
Susan s = new Susan(CurrentImage);
List<IntPoint> corners = s.GetCorners();
}
private void Progressing(string message, bool Show = true)
{
if (Show)
{
lblStatus.Text = message;
Progress.Style = ProgressBarStyle.Continuous;
}
else
{
lblStatus.Text = "...";
Progress.Style = ProgressBarStyle.Blocks;
}
}
长时间运行的表单代码如下所示:
public partial class FrmProcessing : Form
{
public string description { get; set; }
public FrmProcessing(string description)
{
InitializeComponent();
lblDescription.Text = description;
}
// Let the calling method close this form.
public void Close()
{
this.Close();
}
}
【问题讨论】:
-
你确定这样做有什么意义吗?如果某件事始终花费很长时间,那么用“花费很长时间”的微调器来娱乐用户是没有意义的。他们在几次后收到消息,停止查看并启动纸牌。用一个 NotifyIcon 来适应它。或者只是确保他们从不觉得他们必须等待,这太糟糕了。
-
你在哪里创建 FrmProcessing?
-
@Hans.. 这是一个糟糕的建议。这需要“训练”用户知道应用程序没有被锁定。
标签: c# winforms task-parallel-library