当我使用ShowDialog()显示表单时,它会阻止UI和代码,但是我只需要阻止UI而不是代码。
letturalog can3 = new letturalog();
(new System.Threading.Thread(() => {
can3.ShowDialog();
})).Start();
此模式不会阻止代码和UI。
所以我想知道你能否做到
如果您不想阻止代码,那么您想致电 .Show
换句话说,您想要:
can3.Show(this);
this.Enabled = false; //disable the form so the UI is blocked
//...do our stuff now that code is not blocked while the UI is blocked
//All done processing; unblock the UI:
this.Enabled = true;
实际上,这就是所有ShowDialog
操作:禁用该表单,然后重新启用它。在伪代码中:
void ShowDialog(IWindowHandle Owner)
{
this.Show(Owner);
try
{
//Disable the owner form
EnableWindow(Owner, false);
repeat
{
Application.DoEvents();
}
until (this.DialogResult != DialogResult.None);
}
finally
{
//Re-enable the UI!
EnableWindow(owner, true);
}
}
您可以窃取所有这些概念,并用所需的任何东西替换胆量:
void DoStuffWithTheThing()
{
can3.Show();
try
{
//Disable the owner form
this.Enabled = false;
//todo: Solve the P=NP conjecture
}
finally
{
//Re-enable the UI!
this.Enabled = true;
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句