0

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

这是我的代码:

  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();
    }

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

此外,close 方法有一个绿色下划线,说明“隐藏继承的成员 System.Window.Windows.Close() 如果要隐藏,请使用新关键字”

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

4

2 回答 2

6

private void Close()
{
   this.Close();
}

Close在无限递归中调用相同的方法,这会溢出堆栈

我想你的意思是

private void Close()
{
   base.Close();
}
于 2012-06-11T12:43:22.467 回答
1

this.Close()是无限循环的。使用base.Close().

于 2012-06-11T12:43:56.113 回答