.net - 如何终止我的移动应用程序?

标签 .net windows compact-framework mobile

我有这个 Windows 移动应用程序。

我想启动一个 updater.exe 来更新我的移动应用程序。但是我需要在更新程序启动之前停止我的移动应用程序。我该如何实现?

最佳答案

我所做的是,如果您从自己的内部启动更新应用程序,请使用 Process.Start("\Path\To\Updater.exe"); 执行更新程序,然后立即关闭主应用程序(使用 this.Close();Application.Quit();。它应该可以正常工作。

要从更新程序内部终止主应用程序,您必须使用 p/invoke 和系统调用方法来查找并终止主应用程序。它最终应该是这样的(未经测试):

class CloseWindow
{
    [DllImport("coredll.dll")]
    private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

    [DllImport("coredll")]
    public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);

    public const int WM_CLOSE = 0x0010;

    public static void Close(string windowName)
    {
        IntPtr hWnd = FindWindow(null, windowName);
        SendMessage(hWnd, WM_CLOSE, null, null);
    }
}

然后使用 CloseWindow.Close("My Application Title"); 调用它。

关于.net - 如何终止我的移动应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1301953/

相关文章:

c# - 如何获取 RichTextBox 控件中的当前行?

.net - 我是一个进程,消耗多少CPU?

c# - 为什么 .Net 框架类中的静态方法总是线程安全的?

windows - 将自签名 XAP 部署到 Windows Phone 8

windows - SplitView下如何设置CommandBar?

java - 文件系统更新、锁定、计时问题

.net - DataWedge 库 - 摩托罗拉 MC55 条码扫描速度非常慢

c# - 返回结果后,控制流如何保留在异步方法范围内?这类似于变量的闭包吗?

c# - 在 .NET Compact Framework 3.5 的 HttpWebRequest 中指定客户端证书

.net - .net 紧凑框架的开源 Graph 控件库或控件