我有一个需要更新的ClickOnce应用程序。
运行ApplicationDeployment.CurrentDeployment.CheckfForDetailedUpdate()
将返回服务器上有可用更新的详细信息,并在服务器上获取应用程序的正确版本号。
当我运行UpdateAsync
方法时,没有任何反应,程序会在无限循环中挂起,如代码所示。
可能出现什么问题?
这是代码
if (ApplicationDeployment.IsNetworkDeployed)
if (ApplicationDeployment.CurrentDeployment.CheckForUpdate())
{
long downloaded = 0;
bool write = false;
bool updateCompleted = false;
deployment.UpdateCompleted += (sender, e) => updateCompleted = true;
deployment.UpdateProgressChanged += (sender, e) =>
{
//used to write to the log file the first time anything downloads
if (downloaded == 0)
write = true;
downloaded = e.BytesCompleted;
};
deployment.UpdateAsync();
//suspend while updating
while (!updateCompleted)
{
//write is never true implying that nothing gets downloaded
if (write)
{
log.Info(
"Downloaded " + downloaded + " bytes of " + total + ".");
write = false;
}
Thread.Sleep(10);
}
}
答案 0 :(得分:1)
我的猜测是你在while循环中阻塞主应用程序线程,UpdateCompleted
正在等待你的主应用程序线程变为空闲,以便它可以运行。 MSDN文档支持这种猜测:
当异步更新完成或遇到异常时,ClickOnce将在主应用程序线程上引发UpdateCompleted事件。