[英]Unpacking a .cab file and then closing the running process on windows CE 6.0 with .net mobile 3.5
I have a windows CE 6.0 program that uses a .cab file for installation. 我有一个Windows CE 6.0程序,该程序使用.cab文件进行安装。 it incorporates the guide from http://msdn.microsoft.com/en-us/library/aa446487.aspx to support automatic self-updates.
它并入了http://msdn.microsoft.com/zh-cn/library/aa446487.aspx中的指南,以支持自动自我更新。
the program can check for updates just fine, it downloads the update like it should, but when I try to make it unpack the .cab file it just downloaded, it fails. 该程序可以很好地检查更新,它会按应有的方式下载更新,但是当我尝试使其解压缩刚刚下载的.cab文件时,它将失败。
this is my code: 这是我的代码:
void ResponseReceived(IAsyncResult res)
{
try
{
_mResp = (HttpWebResponse)_mReq.EndGetResponse(res);
}
catch (WebException ex)
{
MessageBox.Show(ex.ToString(), "Error");
return;
}
// Allocate data buffer
_dataBuffer = new byte[DataBlockSize];
// Set up progrees bar
_maxVal = (int)_mResp.ContentLength;
pgbDownloadBar.Invoke(new EventHandler(SetProgressMax));
// Open file stream to save received data
_mFs = new FileStream(@"\Application\CCOptimizerSetup.cab",
FileMode.Create);
// Request the first chunk
_mResp.GetResponseStream().BeginRead(_dataBuffer, 0, DataBlockSize,
OnDataRead, this);
}
void OnDataRead(IAsyncResult res)
{
// How many bytes did we get this time
int nBytes = _mResp.GetResponseStream().EndRead(res);
// Write buffer
_mFs.Write(_dataBuffer, 0, nBytes);
// Update progress bar using Invoke()
_pbVal += nBytes;
pgbDownloadBar.Invoke(new EventHandler(UpdateProgressValue));
// Are we done yet?
if (nBytes > 0)
{
// No, keep reading
_mResp.GetResponseStream().BeginRead(_dataBuffer, 0,
DataBlockSize, OnDataRead, this);
}
else
{
// Yes, perform cleanup and update UI.
_mFs.Close();
_mFs = null;
Invoke(new EventHandler(AllDone));
}
}
private void AllDone(object sender, EventArgs e)
{
Cursor.Current = Cursors.Default;
DialogResult dialogresult = MessageBox.Show(@"CCOptimizer has finished downloading. Open now?", "Download complete", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
switch (dialogresult)
{
case DialogResult.OK:
Application.Exit();
Dispose();
Close();
Invoke(new EventHandler(StartProcess));
break;
case DialogResult.Cancel:
Form1 oForm = new Form1();
oForm.Show();
Hide();
break;
}
}
private void StartProcess(object sender, EventArgs e)
{
Process.Start(@"\Application\CCOptimizerSetup.cab", null);
}
It doesn't work though. 虽然不行。 wherever I place the invocation of
StartProcess()
, either it just shuts down with no message or I get an error during unpacking that one of the files i'm trying to update is still in use. 无论我在哪里调用
StartProcess()
,它要么只是关闭而没有任何消息,要么在解压缩过程中出现错误,表明我要更新的文件之一仍在使用中。 During debugging, it just stops the program. 在调试过程中,它只是停止程序。 If I try on an installed version, it very briefly flashes a window, then locks up the machine with the WaitCursor rotating and needs a reboot, although it can install just fine afterwards.
如果我尝试安装的版本,它会短暂地闪烁一个窗口,然后旋转WaitCursor锁定机器,并需要重新启动,尽管之后可以很好地安装它。
How can I close the current program and open a .cab file without having to reboot the machine? 如何关闭当前程序并打开.cab文件,而不必重新启动计算机?
You've got a flaw in your update logic, probably that the app you want to update is the thing checking for updates (it's not entirely clear from the question, but the behavior suggest this is the case). 您的更新逻辑存在缺陷,可能是您要更新的应用是检查更新的事物(问题尚不完全清楚,但行为表明确实如此)。
An application cannot directly update itself because, for what should be fairly obvious reasons, you cannot replace the assemblies that are already loaded and running. 应用程序无法直接更新自身,因为出于显而易见的原因,您不能替换已经加载并正在运行的程序集。
There are, generally speaking, two ways that I have used to get around this. 一般来说,有两种方法可以解决此问题。 Both require a second executable (which in many case I already have as a watchdog app anyway).
两者都需要第二个可执行文件(在许多情况下,无论如何我都已经拥有它作为看门狗应用程序)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.