.NET让我在C#应用程序的进程ID [英] .NET get process ID of my application in C#

查看:164
本文介绍了.NET让我在C#应用程序的进程ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有.NET的方式来获取进程ID(或只是过程)的程序进行调用?

Is there a way in .NET to get the process ID (or just the Process) of the program making the call?

Process.GetCurrentProcess()得到过程这是当前活动,即一个用户是使用权即可。我需要我自己的应用程序的过程这很可能是未激活我打电话的时间。

Process.GetCurrentProcess() gets the Process that's currently active, i.e., the one the user is using right then. I need the Process of my own app which is likely not active at the time I'm calling it.

我可以打电话给 GetCurrentProcess() Window.Activated 并将其存储在私有字段,但没有绝对的担保(我相信),如果应用程序在后台打开该事件永远不会触发。

I could call GetCurrentProcess() on Window.Activated and store it in a private field, but there's no absolute guaranty (I believe) that that event will ever fire if the app is opened in the background.

推荐答案

您误会了.. <一HREF =https://msdn.microsoft.com/en-us/library/system.diagnostics.process.getcurrentprocess.aspx相对=nofollow> GetCurrentProcess 回报:

与运行调用应用程序的过程中资源相关联的一个新的进程的组成部分。

A new Process component associated with the process resource that is running the calling application.

它不(一定)返回与当前活动窗口相关联的过程。

It does not (necessarily) return the process associated with the currently active window.

在该文档是指主动的过程,这意味着当前执行过程中,即调用进程。活动窗口可能或可能不属于该活动过程中,由于场的过程中可以不拥有前台窗口执行,或在所有的任何窗口。

When the docs refer to the "active" process, that means the currently executing process, i.e. the calling process. The active window may or may not belong to the active process, since of course a process can execute without owning the foreground window, or any window at all.

这篇关于.NET让我在C#应用程序的进程ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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