繁体   English   中英

解压缩.cab文件,然后关闭带有.net mobile 3.5的Windows CE 6.0上的运行过程

[英]Unpacking a .cab file and then closing the running process on windows CE 6.0 with .net mobile 3.5

我有一个Windows CE 6.0程序,该程序使用.cab文件进行安装。 它并入了http://msdn.microsoft.com/zh-cn/library/aa446487.aspx中的指南,以支持自动自我更新。

该程序可以很好地检查更新,它会按应有的方式下载更新,但是当我尝试使其解压缩刚刚下载的.cab文件时,它将失败。

这是我的代码:

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);
}

虽然不行。 无论我在哪里调用StartProcess() ,它要么只是关闭而没有任何消息,要么在解压缩过程中出现错误,表明我要更新的文件之一仍在使用中。 在调试过程中,它只是停止程序。 如果我尝试安装的版本,它会短暂地闪烁一个窗口,然后旋转WaitCursor锁定机器,并需要重新启动,尽管之后可以很好地安装它。

如何关闭当前程序并打开.cab文件,而不必重新启动计算机?

您的更新逻辑存在缺陷,可能是您要更新的应用是检查更新的事物(问题尚不完全清楚,但行为表明确实如此)。

应用程序无法直接更新自身,因为出于显而易见的原因,您不能替换已经加载并正在运行的程序集。

一般来说,有两种方法可以解决此问题。 两者都需要第二个可执行文件(在许多情况下,无论如何我都已经拥有它作为看门狗应用程序)。

  1. 而不是直接启动您的应用程序,而是先启动一些“更新程序”应用程序。 该应用程序可以检查更新,通知用户,下载以及安装/覆盖目标应用程序,因为它尚未运行。 然后,更新程序将在完成目标应用程序或不需要更新步骤的情况下运行目标应用程序。
  2. 与其直接启动您的应用程序,不如直接启动一些“ bootstrap”应用程序。 引导程序会在本地临时存储中查找任何更新文件,如果它们存在则执行它们,然后运行普通应用程序。 让应用程序本身检查更新并将其拉到临时存储位置。 提取更新后,将其关闭并重新启动引导程序,然后将应用更新。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM