什么是Windows Service中的Application.ExecutablePath

Ton*_*nyP 4 c# windows winforms c#-4.0

在Windows窗体应用程序中,我使用Application.Executable路径来访问App.config.

我需要在Windows服务中找到app.config.那会是什么?

Bra*_*tie 8

有两种选择:

System.Reflection.Assembly.GetExecutingAssembly().Location
Run Code Online (Sandbox Code Playgroud)

对于当前的组装.或者,您可以从类型派生它:

System.Reflection.Assembly.GetAssembly(typeof(MyAssemblyType)).Location
Run Code Online (Sandbox Code Playgroud)

然后(在任一个上)你可以Path.GetDirectoryName用来获取它来自的文件夹(假设你的app.config在同一个目录中).