2016-04-03 83 views
0

在我的C#WPF应用程序中,我正在检查是否需要安装新版本。如果是这样,我想打破当前的过程,并开始安装。安装程序是使用NSIS包开发的。 问题是,有时只有来自NSIS安装程序的用户帐户控制对话框出现并安装进程中断。从c#wpf应用程序运行安装过程

enter image description here

如何确保安装过程中,每次执行?

这是我在应用程序启动时的代码。

protected override void OnStartup(StartupEventArgs e) 
    { 
     try 
     { 
      //Disable shutdown when the dialog closes 
      Current.ShutdownMode = ShutdownMode.OnExplicitShutdown; 

      if (IfUpdateRequired()) 
      { 
       System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(sessionCtx.AutoUpdateVersionInfo.SetupPath); 
       //This should not block current program 
       startInfo.UseShellExecute = true; 
       startInfo.Verb = "runas"; 
       System.Diagnostics.Process.Start(startInfo); 
       this.Shutdown(); 
      } 
      else 
      { 
       base.OnStartup(e); 
      } 
     } 
     catch (Exception ex) 
     { 

     } 
    } 
+0

你可能会添加一个“启动屏幕通知系统修改”的屏幕截图,因为我不太明白你在说什么。 – Anders

+0

我的意思是“用户帐户控制对话框”。 – iljon

+0

“安装过程中断”时会发生什么?有没有任何错误信息或类似的东西? – Anders

回答

1

我唯一的猜测是子进程在你的进程退出之前还没有完全启动。 ShellExecute被允许异步执行其操作。

如果这是原因,那么您应该能够在致电this.Shutdown()之前通过睡一会儿来解决它。也许等待10秒左右?或者打电话给WaitForInputIdle(9999)。或者,也许你可以检查响应流程属性?

+0

看来你的建议解决了这个问题。非常感谢。 – iljon

相关问题