Windows应用程序中的等待窗口 [英] Wait window in a windows application
问题描述
我基本上需要向用户显示一个等待窗口。为此,我在应用程序中放置了两个单独的窗口形式。第一种形式是带有按钮的主要形式。第二个是空的,只有标签文本。在Form1中单击按钮后,我将执行以下操作
I basically need to show a wait window to the user. For this i have put two seperate window forms in the application. the first form is the main form with a button. The second one is a empty one with just a label text. On click of the button in Form1 i do the below
Form2 f = new Form2();
f.Show();
Thread.Sleep(2000);
f.Close();
我的想法是向用户显示等待时间2秒。但是,当我这样做时,由于其中的标签为空白,因此未完全加载Form 2。
My idea here is to show the wait window to the user for 2 second. But when i do this the Form 2 is not completely loaded because of which the label in it is blank. Please let me know your inputs on this.
推荐答案
这是因为您可能在同一线程(UI线程)中做了一些冗长的操作。您应该在新线程(请参阅Thread类)中执行代码,或者至少从冗长的操作内部定期调用Application.DoEvents来更新UI。
That's because you probably do some lengthy operation in the same thread (UI thread). You should execute your code in a new thread (see Thread class) or at least call Application.DoEvents periodically from inside your lengthy operation to update the UI.
这篇关于Windows应用程序中的等待窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!