这是后续这个答案 https://stackoverflow.com/a/616588/37759(及其评论)。从程序集获取可执行文件名称与从进程获取可执行文件名称有什么区别?
System.Reflection.Assembly.GetCallingAssembly.GetEntryAssembly().CodeBase
vs
Process.GetCurrentProcess().ProcessName
我假设这些一直都是一样的?不?有优点和缺点吗?
它们不一定相同。将这两个程序编译为同一目录中的控制台应用程序:
// 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);
}
}
Output:
Process: Test
Entry assembly: file:///c:/Users/Jon/Test/Test2.EXE
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)