我正在尝试使用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/