当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Pass Parameters to Main(string[] args) of Windows Services

问题描述:

I need to pass parameters to Main(string[] args) of windows service, I'm able to pass parameters to void OnStart(string[] args) through the properties of service by using

How to pass parameters to Windows Service?

sample code:

static void Main(string[] args)////How to pass args to this function

{

//// some code

}

protected override void OnStart(string[] args)////by using above link i can pass parameters to this function

{

////some code

}

Note : I used project properties to pass the args to main() but it can't help in real time.

Is this a right way to do it because I can't find any information regarding this?

Edit 1:

I refered this How to pass parameters in windows service from Installer to Main function in Program.cs? but i didnt get much information why we cant pass?

Edit 2:

My goal is to pass a Raygun key to Main(String[] args) then log the errors to the Raygun Website,so based on the key it will log errors to the particular version. So i need to pass Raygun key dynamically to the service, i can pass the key through the Service properties, then it will log only onstart(...) level so if any exception are handled at main() level i can't able to log.So i need to initialize the below code at main method level or while Service Starts

_raygunClient = new RaygunClient("Dynamic_Key");

service will start manually at any time for development prospective.

网友答案:

Pass the Raygun key as commandline arguments. Set the key at installation time. There is no need for dynamic arguments.

分享给朋友:
您可能感兴趣的文章:
随机阅读: