任务管理器中存在流程 [英] Process Exist in Task Manager

查看:109
本文介绍了任务管理器中存在流程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将如何检查Windows Task Manager中是否存在我的创建过程??
请帮助我...

How will i check that my creating process is exist in Windows Task Manager???
Please Help me...

推荐答案

或者,如果您知道进程的名称,则可以使用:Process.GetProcessesByName方法(字符串) [ ^ ].

但是,如果您已经创建了该进程,则可以使用以下示例创建它: Process.Start方法(ProcessStartInfo) [^ ].如果有的话,该方法将返回已启动的过程,可将其用于以后的调查/交流等.因此,将返回值置于变量中可以消除查找过程的需要.
Or if you know the name of the process you can use: Process.GetProcessesByName Method (String)[^].

However, if you have created the process have you created it with for example: Process.Start Method (ProcessStartInfo)[^]. If you have, that method returns the started process which you can use for later investigation/communication etc. So putting the return value to a variable may eliminate the need to find the process.


使用GetProcesses()
Use GetProcesses()
System.Diagnostics.Process.GetProcesses(machinename)



有关更多详细信息,请阅读: http://msdn. microsoft.com/en-us/library/system.diagnostics.process.getprocesses(v=vs.71).aspx [



For more details read : http://msdn.microsoft.com/en-us/library/system.diagnostics.process.getprocesses(v=vs.71).aspx[^]


答案由米卡(Mika)需要澄清和改进.首先,请看我对他的回答的评论.

好像您只知道进程的名称一样,没有可靠的方法知道正在运行的进程中找到的项目就是您所需要的.

我假设您正在谈论的是使用System.Diagnostics.Project.Start作为当前进程的子进程启动的进程.此名称下有几种方法,所有这些方法都可以检查进程的状态.首先,您需要获取有问题的Project类型的实例.有5种静态方法;它们中的每一个都返回此实例,并且唯一的非静态(实例)方法是使用构造函数创建的实例(可能是分配了ProcessInfo的实例)调用的.对于此方法,您应该首先通过其布尔返回值检查启动是否成功.因此,在所有情况下,您都有类Process的实例.
请参阅
http://msdn.microsoft.com/en-us/library/system.diagnostics .process.aspx [ ^ ].

现在,您需要检查它的当前状态.一种实现此目的的方法是属性ExitCode.您需要假定该过程已成功启动(请参见上文),并且使用了Process的相同实例.如果获得退出代码值,则表示该过程已退出.如果不是,您将获得一个例外.您无法获得异常NotSupportedException,因为您知道该过程启动成功.当您有异常InvalidOperationException时,由于上述原因,句柄无效就不会是这种情况.因此,此异常表示该进程正在运行.在检查ExitCode时捕获此异常,您已完成.

请参阅 http://msdn.microsoft.com/en-us/library/system .diagnostics.process.exitcode.aspx [ ^ ].

或者,您可以检查属性ExitTime,请参见 http://msdn .microsoft.com/en-us/library/system.diagnostics.process.exittime.aspx [
The answer by Mika need clarification and improvements. First of all, see my comments to his answer.

As if you only know the process by its name, there is no reliable way to know that the project found among running processes is the one you need.

I assume you are talking about a process you start as a child process of your current process using System.Diagnostics.Project.Start. There are several methods under this name, and all of them allow to check up the status of the process. First of all, you need to get an instance of the Project type in question. There are 5 static methods; and each of them returns this instance, and the only non-static (instance) method is called with the instance created with the constructor, presumably with assigned ProcessInfo. For this method, you should first check up if the start was successful, by its Boolean return value. So, in all cases, you have an instance of the class Process.

See http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx[^].

Now, you need to check up it''s current status. One method to do this is the property ExitCode. You need to assume that the process was successfully started (see above) and you use the same instance of Process. If you get an exit code value, it means that the process is exited. If it is not, you will get an exception. You cannot get the exception NotSupportedException because you know that the process start was successful. When you have the exception InvalidOperationException, it cannot be the case when a handle is invalid, by the reason explained above. So, this exception is the indication that the process is running. Catch this exception while checking ExitCode and you are done.

See http://msdn.microsoft.com/en-us/library/system.diagnostics.process.exitcode.aspx[^].

Alternatively, you can check up the property ExitTime, see http://msdn.microsoft.com/en-us/library/system.diagnostics.process.exittime.aspx[^]. You will need to handle exceptions in the same way as in the method based on ExitCode.

Finally, handle the event Exited to capture the moment of exiting:

myChildProcess.Exited += (sender, eventArgs) => {
    this.ChildIsRunning = false; //for example, you can introduce such flag as your declaring class's field
}



请参阅
http://msdn.microsoft.com/en-us/library/system .diagnostics.process.exited.aspx [ ^ ].

—SA



See http://msdn.microsoft.com/en-us/library/system.diagnostics.process.exited.aspx[^].

—SA


这篇关于任务管理器中存在流程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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