0
我有一個在我的應用程序啓動時運行的以下方法,我首先顯示維護屏幕。方法運行後,我想顯示我的登錄屏幕。但是,登錄屏幕未打開。如果我註釋掉顯示維護屏幕的代碼,它工作正常。show()命令不會打開窗口Wpf
private void Application_Startup(object sender, StartupEventArgs e)
{
ILocalDbDataService _locDataService =new LocalDbDataService();
Maintenance mWin = new Maintenance();
mWin.Show();
MaintenanceViewModel maintenanceViewModel = Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance<MaintenanceViewModel>();
maintenanceViewModel.RunMaintenance();
Login lWin = new Login();
lWin.Show();//This windows doesn't open
}
public class MaintenanceViewModel : ViewModelBase
{
private readonly ILocalDbDataService _localDbDataService;
public MaintenanceViewModel(ILocalDbDataService localDbDataService)
{
_localDbDataService = localDbDataService;
}
public void RunMaintenance()
{
bool result= _localDbDataService.RunTransArchiveMaintenance();
MessengerInstance.Send(new NotificationMessage("CloseMaintenance"));
}
}
public partial class Maintenance : Window
{
public Maintenance()
{
InitializeComponent();
Messenger.Default.Register<NotificationMessage>(this, msg =>
{
if (msg.Notification == "CloseMaintenance")
{
this.Close();
}
});
}
}