C# Window.ShowDialog的奇怪行为
我的WPF应用程序中有一个奇怪的行为,希望有人能给我一个线索。我在启动时覆盖了以下应用程序:C# Window.ShowDialog的奇怪行为,c#,.net,wpf,C#,.net,Wpf,我的WPF应用程序中有一个奇怪的行为,希望有人能给我一个线索。我在启动时覆盖了以下应用程序: protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); try { if (AppMutex.WaitOne(TimeSpan.Zero, true)) { IoC.Ins
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
try
{
if (AppMutex.WaitOne(TimeSpan.Zero, true))
{
IoC.Instance.RegisterInstance(LogManager.GetLogger("MainLogger"));
Init();
var mainView = new MainView()
{
DataContext = IoC.Instance.MainViewModel
};
mainView.ShowDialog();
}
}
catch (Exception exception)
{
IoC.Instance.Log.Error(exception);
throw;
}
finally
{
AppMutex.ReleaseMutex();
}
}
此处,MainView是System.Windows.Window的子类,没有重写的方法。
问题在于mainView.ShowDialog()。该行正在执行,没有任何异常,但未显示窗口。线程只是向前运行,应用程序终止。
有人知道这种行为吗?
提前谢谢
UPD:
如果我将MessageBox.ShowDialog()放在此调用之前,则MessageBox.ShowDialog执行正确,但mainView.ShowDialog会引发异常:
无法设置可见性或在窗口关闭后调用Show、ShowDialog或WindowInteropHelper.EnsureHandle
带有null InnerException
UPD:我得到了符号并检查了VerifyCanShow:
private void VerifyCanShow()
{
if (this._disposed)
throw new InvalidOperationException(SR.Get("ReshowNotAllowed"));
}
看起来我的主视图在某种程度上得到了处理…您需要将
应用程序.ShutdownMode
设置为OnExplicitShutdown
然后,您可以在对话框关闭后手动关闭应用程序
mainView.ShowDialog();
Shutdown();
中断
ShowDialog
并逐步查看失败的位置。它可能是OnLoad
中的某个东西?我没有这个库的符号,但是如果我能得到它们,它们能有什么帮助?没有抛出异常,我应该搜索什么?它可能有在表单加载时检查的需求。如果它们丢失了,它可能只是故意退出。或者在MainView
构造函数中放置一个breakpoint
,看看那里发生了什么。
mainView.ShowDialog();
Shutdown();