在处理完成之前显示动态时间的等待表单
Show Wait Form for dynamic time until processing is done
我在 Whosebug、Code Project、C# Corner 和许多其他论坛的许多线程中进行了搜索。
我的问题被克隆了。但我没有任何令人满意的解决方案。
我想展示一个等待表单,它会在有某种后台工作时出现。后台工作可能包括打开表单、填充网格视图等批处理和处理命令。
private void newVendorBtn_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
if (newVendor==null||newVendor.Text=="")
{
SplashScreenManager.ShowForm(this, typeof(WaitForm1), true, true, false);
newVendor = new newVendorForm();
newVendor.MdiParent = this;
for (int i = 0; i <= 100; i++)
{
SplashScreenManager.Default.SetWaitFormDescription(i.ToString() + "%");
Thread.Sleep(5);
}
SplashScreenManager.CloseForm(true);
newVendor.Show();
}
else if(CheckOpened(newVendor.Text))
{
newVendor.WindowState = FormWindowState.Normal;
newVendor.Show();
newVendor.Focus();
}
//newvendorBool = addPanel(ref newVendorDP, newVendor, ref newvendorBool, "New Vendor");
}
现在问题来了,对于依赖于机器处理的动态时间,等待应该如何出现。
如果应用程序在最新的快速机器(即 i7、i5、其他等)上是 运行,等待表格出现的时间应该更少,就像在 Pentium 3 上一样,4 它应该出现很长时间,直到处理完成。
我正在开发 c# Winforms 应用程序。
这里的伪代码向您展示了这个概念的一个例子。您可以为 C# 修改它:
newVendorBtn_ItemClick{
SplashScreenManager.ShowForm(this, typeof(WaitForm1), true, true, false);
newVendor = new newVendorForm();
newVendor.MdiParent = this;
//This triggers the newVendor_Load
newVendor.Show();
//newVendor is done loading, close the splash screen
SplashScreenManager.CloseForm(true);
}
newVendor_Load{
//newVendor Form does some tasks when it's first loaded
//these tasks will take different times to complete on different computers
//as each is completed, the splash screen is updated.
performLoadingTask1();
SplashScreenManager.Default.SetWaitFormDescription("20% complete");
performLoadingTask2();
SplashScreenManager.Default.SetWaitFormDescription("40% complete");
performLoadingTask3();
SplashScreenManager.Default.SetWaitFormDescription("60% complete");
performLoadingTask4();
SplashScreenManager.Default.SetWaitFormDescription("80% complete");
performLoadingTask5();
SplashScreenManager.Default.SetWaitFormDescription("100% complete");
}
我在 Whosebug、Code Project、C# Corner 和许多其他论坛的许多线程中进行了搜索。 我的问题被克隆了。但我没有任何令人满意的解决方案。 我想展示一个等待表单,它会在有某种后台工作时出现。后台工作可能包括打开表单、填充网格视图等批处理和处理命令。
private void newVendorBtn_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
if (newVendor==null||newVendor.Text=="")
{
SplashScreenManager.ShowForm(this, typeof(WaitForm1), true, true, false);
newVendor = new newVendorForm();
newVendor.MdiParent = this;
for (int i = 0; i <= 100; i++)
{
SplashScreenManager.Default.SetWaitFormDescription(i.ToString() + "%");
Thread.Sleep(5);
}
SplashScreenManager.CloseForm(true);
newVendor.Show();
}
else if(CheckOpened(newVendor.Text))
{
newVendor.WindowState = FormWindowState.Normal;
newVendor.Show();
newVendor.Focus();
}
//newvendorBool = addPanel(ref newVendorDP, newVendor, ref newvendorBool, "New Vendor");
}
现在问题来了,对于依赖于机器处理的动态时间,等待应该如何出现。 如果应用程序在最新的快速机器(即 i7、i5、其他等)上是 运行,等待表格出现的时间应该更少,就像在 Pentium 3 上一样,4 它应该出现很长时间,直到处理完成。 我正在开发 c# Winforms 应用程序。
这里的伪代码向您展示了这个概念的一个例子。您可以为 C# 修改它:
newVendorBtn_ItemClick{
SplashScreenManager.ShowForm(this, typeof(WaitForm1), true, true, false);
newVendor = new newVendorForm();
newVendor.MdiParent = this;
//This triggers the newVendor_Load
newVendor.Show();
//newVendor is done loading, close the splash screen
SplashScreenManager.CloseForm(true);
}
newVendor_Load{
//newVendor Form does some tasks when it's first loaded
//these tasks will take different times to complete on different computers
//as each is completed, the splash screen is updated.
performLoadingTask1();
SplashScreenManager.Default.SetWaitFormDescription("20% complete");
performLoadingTask2();
SplashScreenManager.Default.SetWaitFormDescription("40% complete");
performLoadingTask3();
SplashScreenManager.Default.SetWaitFormDescription("60% complete");
performLoadingTask4();
SplashScreenManager.Default.SetWaitFormDescription("80% complete");
performLoadingTask5();
SplashScreenManager.Default.SetWaitFormDescription("100% complete");
}