コード例 #1
0
        protected virtual void Run(Window window)
        {
            WPFApplication application = Domain.Current.Application as WPFApplication ?? throw new InitializeException("Application is not wpf");

            if (window is null)
            {
                application.Run();
                return;
            }

            Context ??= window;
            if (window != Context)
            {
                throw new ArgumentException($"{nameof(window)} not reference equals with {nameof(Context)}");
            }

            Context.Closed += OnFormClosed;
            application.Run(Context);
        }
コード例 #2
0
 /// <summary>
 /// 程序启动
 /// </summary>
 /// <param name="e"></param>
 /// <returns></returns>
 protected override bool OnStartup(Microsoft.VisualBasic.ApplicationServices.StartupEventArgs e)
 {
     try
     {
         if (WPFApplication != null)
         {
             WPFApplication.Run();
         }
         else if (MainWindow != null)
         {
             System.Windows.Forms.Application.Run(MainWindow);
         }
     }
     catch (Exception ex)
     {
         ex.ToString().WriteToLog("", log4net.Core.Level.Error);
         System.Windows.MessageBox.Show("系统异常,请联系管理员!", "提示信息", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error, System.Windows.MessageBoxResult.OK);
         System.Environment.Exit(System.Environment.ExitCode);
     }
     return(false);
 }