我要在MainForm进行一些数据库相关工作时显示带有进度栏的新表单。我读到您不想将UI传递给新线程,所以我想知道解决此问题的最佳解决方案是什么?
我无法在另一个线程上执行与数据库相关的工作,因为它使用了十二个对UI和MainForm的调用。我也不能使用Application.DoEvents()
,因为MainForm的线程正在类中工作,据我所知,您不应对类的父类进行任何调用。
任何建议,将不胜感激!
编辑
为了澄清我实际上想知道的事情:
我的程序看起来像这样:
... Content = DatabaseClass.LoadContent();
ApplyContentToUI(Content);
我想做的是以下几点:
//Show a form here with a progressbar
... Content = DatabaseClass.LoadContent();
ApplyContentToUI(Content);
//Close the form here
但是,自从执行ApplyContentToUI的时间开始就是aprox。我希望1秒钟执行以下操作:
//Show a form here with a progressbar
... Content = DatabaseClass.LoadContent();
//Close the form here
ApplyContentToUI(Content);
如果您与我不同,如果需要在重新加载UI时显示进度栏,建议您查看下面的评论和答案。
我是一名优秀的程序员,十分优秀!