当Process.Start返回null时,查找进程ID? [英] Find process id when Process.Start returns null?

查看:64
本文介绍了当Process.Start返回null时,查找进程ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我尝试通过直接调用 Process.Start(filepath)来打开图像文件,视频或网站,则通常会成功.但是,Process.Start的返回值有时为null.(如此处所述)

If I try to open an image file, or video, or website by calling Process.Start(filepath) directly, then it will typically succeed. However, the return value of Process.Start will sometimes be null. (As discussed here)

我需要知道相关进程的ID,以便以后可以检索它并在必要时将其关闭.(用例:用户使用我的程序打开一个图像文件,并想使用我的程序将其关闭).但是,检索返回null的进程的进程ID有点困难:P

I need to know the associated process's id so that I can retrieve it later and close it if necessary. (Use case: User opens an image file using my program, and would like to close it using my program) However, it's kind of hard to retrieve the process id of a process that returns null :P

除了可能直接指定我们可能会遇到的每种文件使用哪种程序之外,其他关于我应该如何处理的建议?

Any suggestions on how I should go about this, other than maybe specifying directly which program to use for each type of file we may encounter?

推荐答案

您必须直接指定要使用哪个程序来获取进程ID.我可以想象您会问os,因为os列出了这些扩展,因此每个扩展都使用什么程序.

You have to specify directly which program to use to get the id of the process. I can imagine you can ask the os what program to use for each extensions as the os has a list of those.

这篇关于当Process.Start返回null时,查找进程ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆