C#:杀死打开的特定文件而不是所有实例
我正在尝试通过 Process 在我的应用程序中打开 Excel 文件。 当表单关闭时,我想自动关闭该文件。 我面临的问题是,即使我指定打开的 Excel 的 PID 进程。 当我运行kill指令时,所有其他打开的excel文件都将关闭,而不是我需要的特定文件。
请你帮助我好吗 。
File.WriteAllBytes(filePath, bytes);
proc = new Process();
proc = Process.Start(filePath);
processId = proc.Id; //keep PID to kill that process
proc.WaitForInputIdle(); //Set focus on opened file
SetForegroundWindow(this.Handle);
proc.Dispose();
// killing the process after file use
Process processes = Process.GetProcessById(processId);
processes.Kill();
I'm trying to open an excel file in my application via Process.
When the form is closed I want to close that file automatically .
The issue that I'm facing is even if I specify the PID process of the Excel opened .
When I run the kill instruction, all the other excels file opened will close and not specifically the one that I need.
Could you please help me .
File.WriteAllBytes(filePath, bytes);
proc = new Process();
proc = Process.Start(filePath);
processId = proc.Id; //keep PID to kill that process
proc.WaitForInputIdle(); //Set focus on opened file
SetForegroundWindow(this.Handle);
proc.Dispose();
// killing the process after file use
Process processes = Process.GetProcessById(processId);
processes.Kill();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论