我搜索了stackoverflow,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应用程序。
答案 0 :(得分:0)
这里的伪代码向您展示了这个概念的一个例子。您可以为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");
}