c# - 使用 Process.Start 启动 WPF 应用程序

标签 c# wpf process

我正在尝试使用Process.Start启动wpf应用程序。当我在 explorer.exe 中双击该进程来启动该进程时,它会正常启动;但是,当我尝试使用以下代码片段时:

var programPath = @"C:\Users\user\Documents\Program Directory\program.exe";
if(!File.Exists(programPath))
{
     MessageBox.Show("The program.exe file does not exist! Cannot launch.");
     return;
}
Process.Start(programPath);

我的 WPF 进程在任务管理器中短暂闪烁,然后立即关闭。

最佳答案

我这样解决了问题:

Process proc = new Process();
proc.StartInfo.FileName = programPath;
proc.StartInfo.WorkingDirectory = Path.GetDirectoryName(programPath);
proc.Start();

技巧是将工作目录设置为 WPF 应用程序的路径,而不是启动应用程序的工作目录。

关于c# - 使用 Process.Start 启动 WPF 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19969693/

相关文章:

c# - MVVM Light Messenger 接收方法

c# - WPF 更新的 Progress<T> 缓冲

c - 枚举当前加载的所有共享对象的所有 ELF 部分

c# - 编译 eAccelerator 解码 PHP 编码文件

C#:如何在 GMap.NET 中生成 map 中心附近的随机位置?

c# - WPF DataGrid 列标题使用自定义样式调整大小

node.js - Nodejs获取相对于process.cwd()的绝对路径

python - 运行后如何在后台启动 python 脚本?

c# - 如何在每个第二个引号处拆分

c# - 当需要保留某个执行顺序时运行一堆异步任务