我有这个 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/