C# 单击一次&x2B;重启=打开浏览器?
我正在部署ClickOnce应用程序,并希望在更新后重新启动该应用程序。因此,我编写了以下代码:C# 单击一次&x2B;重启=打开浏览器?,c#,wpf,clickonce,updates,C#,Wpf,Clickonce,Updates,我正在部署ClickOnce应用程序,并希望在更新后重新启动该应用程序。因此,我编写了以下代码: private async void updateCheck() { using (var releaser = await _asyncLock.LockAsync()) { UpdateCheckInfo info = null; bool updateAvailable = false;
private async void updateCheck()
{
using (var releaser = await _asyncLock.LockAsync())
{
UpdateCheckInfo info = null;
bool updateAvailable = false;
if (ApplicationDeployment.IsNetworkDeployed)
{
ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;
ad.UpdateCompleted += new System.ComponentModel.AsyncCompletedEventHandler(Ad_UpdateCompleted);
try
{
updateAvailable = ad.CheckForUpdate(false);
info = ad.CheckForDetailedUpdate();
}
catch (DeploymentDownloadException dde)
{
MessageBox.Show("The new version of the application cannot be downloaded at this time. \n\nPlease check your network connection, or try again later. Error: " + dde.Message);
return;
}
catch (InvalidDeploymentException ide)
{
MessageBox.Show("Cannot check for a new version of the application. The ClickOnce deployment is corrupt. Please redeploy the application and try again. Error: " + ide.Message);
return;
}
catch (InvalidOperationException ioe)
{
MessageBox.Show("This application cannot be updated. It is likely not a ClickOnce application. Error: " + ioe.Message);
return;
}
if (/*info.UpdateAvailable*/ updateAvailable)
{
Boolean doUpdate = true;
if (!info.IsUpdateRequired)
{
MessageBoxResult dr = MessageBox.Show("An update is available. Would you like to update the application now?", "Update Available", MessageBoxButton.OKCancel);
if (!(MessageBoxResult.OK == dr))
{
doUpdate = false;
}
}
else
{
// Display a message that the app MUST reboot. Display the minimum required version.
MessageBox.Show("This application has detected a mandatory update from your current " +
"version to version " + info.MinimumRequiredVersion.ToString() +
". The application will now install the update and restart.",
"Update Available", MessageBoxButton.OK,
MessageBoxImage.Information);
}
if (doUpdate)
{
try
{
//ad.Update();
ad.UpdateAsync();
}
catch (DeploymentDownloadException dde)
{
MessageBox.Show("Cannot install the latest version of the application. \n\nPlease check your network connection, or try again later. Error: " + dde);
return;
}
}
}
}
}
}
private void Ad_UpdateCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
if (e.Error == null)
{
MessageBox.Show("The application has been upgraded, and will now restart.");
String ApplicationEntryPoint = ApplicationDeployment.CurrentDeployment.UpdatedApplicationFullName;
Process.Start(ApplicationEntryPoint);
Application.Current.Shutdown();
}
}
在UpdatedApplicationFullName中输入存储部署包的网站的URL。因此Process.Start(ApplicationEntryPoint)会打开一个浏览器窗口,并再次尝试下载包
我想要的行为是Process.Start(…)打开新的更新应用程序
有人知道我做错了什么吗
谢谢。您是否尝试过更改
进程.Start(ApplicationEntryPoint)代码>到进程.Start(Assembly.GetEntryAssembly().Location)代码>?您好,我试过这个,它会重新启动应用程序可执行文件的一些实例,但似乎不正确。我添加了一个状态栏字段,它应该显示以下值ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString();在重新启动的值中,没有显示任何内容。我认为这可能是因为它直接启动exe而不是.application文件。