加载页面 - >堆栈溢出

0 c# stack-overflow loading

好吧,我只是想创建一个基本的加载页面,所以我有一些性感的页面出现(没有做任何加载)只是在我的真实表单出现之前显示几秒钟

这是我的代码:

  public partial class LoadingPage : Window
{
    System.Threading.Thread iThread;

    public LoadingPage()
    {
        InitializeComponent();
    }

    private void Refresh()
    {
        System.Threading.Thread.Sleep(900);
        MainWindow iMain = new MainWindow();
        iMain.ShowDialog();
        this.Dispatcher.Invoke(new Action(Close));
    }

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
    iThread = new System.Threading.Thread(new ThreadStart(Refresh));
    iThread.SetApartmentState(System.Threading.ApartmentState.STA);
    iThread.Start();   
    }

    private void Close()
    {
        this.Close();
    }
Run Code Online (Sandbox Code Playgroud)

这可以工作,但会导致堆栈溢出,并且在主页面打开时不会关闭加载窗口.

此外,close方法有一个绿色下划线说"隐藏继承的成员System.Window.Windows.Close()使用new关键字,如果隐藏是有意的"

问题是:是什么导致堆栈溢出?

Att*_*ila 6

private void Close()
{
   this.Close();
}
Run Code Online (Sandbox Code Playgroud)

Close在无限递归中调用它,它会溢出堆栈

我想你的意思

private void Close()
{
   base.Close();
}
Run Code Online (Sandbox Code Playgroud)