0

我在 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 应用程序。

4

1 回答 1

1

这是向您展示此概念的示例的伪代码。您可以为 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");

}
于 2015-08-05T19:39:10.437 回答