显示等待表单的动态时间,直到处理完成
本文关键字:处理 时间 等待表 等待 表单 动态 显示 | 更新日期: 2023-09-27 18:05:48
我在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,其他等),等待表单应该出现更少的时间,如果是在奔腾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");
}