2011-12-06 80 views

回答

4

ProcessName是操作系统主机进程名称。

Assembly CodeBase指向给定进程中的程序集。相同的程序集可以由不同的进程托管。

+0

Jon Skeet的好例子http://stackoverflow.com/a/8406779/37759 –

3

不,他们不需要返回相同的值。

碰巧,我就遇到了这个“疑难杂症”最近:他们可以返回取决于是否你直接运行.exe文件不同的值,或从MSVS调试器的内部:

How do I get the .exe name of a C# console application?

这只是一个例子 - 我确定可能会有其他人。

'希望有帮助!

4

它们不一定相同。编译这两个程序在同一目录下的控制台应用程序:

// In Test.cs, compile to Test.exe 
using System; 
using System.Reflection; 

public static class Program 
{ 
    static void Main(string[] args) 
    { 
     AppDomain.CreateDomain("NewDomain").ExecuteAssembly("Test2.exe"); 
    } 
} 

// In Test2.cs, compile to Test2.exe 
using System; 
using System.Diagnostics; 
using System.Reflection; 

class Test2 
{ 
    static void Main() 
    { 
     Console.WriteLine("Process: {0}", 
          Process.GetCurrentProcess().ProcessName); 
     Console.WriteLine("Entry assembly: {0}", 
          Assembly.GetEntryAssembly().CodeBase); 
    } 
} 

输出:

Process: Test 
Entry assembly: file:///c:/Users/Jon/Test/Test2.EXE 
相关问题