Questions and Answers on any aspect of .NET. Now closed.
In java you can set flags (-d) sort of like system arguements, but can be read from anywhere in the application.
Is there an equivelant in dotnet?
The reason I need this is for testing a distributed program on my one machine. I planned on launching a test program to use my distributed library multiple times, but need a way to pass a port number for each instance of the library being run.
If the answer to the first question is 'no', suggestions for other ways to do this woiuld be appreciated.
anon for this one
Friday, July 07, 2006
You could use static properties of a class (I use a class based on the Singleton pattern) so it is accessible to any caller in the application for this kind of value that would be parsed and assigned in the Main() function from the command line arguments provided.
Saturday, July 08, 2006
Did you google it? There are tons of references to reading command line arguments into a .net app.
It seems i'm not clear enough in my original or second post. To the last poster, its a library, I'm quite aware on how to pass command line arguements. I was talking about APPLICATION WIDE system variables that could be set by flagging the CLR.
This way I don't have to take command line arguements from a program i'm using to test the library, and find some way to pass it to an object in the library...
arg. the annon guy again.
Sunday, July 09, 2006
From my understanding of what you are doing, you are trying to create multiple instances of your class from a calling/test program, with each having a different port number.
If that is the case, why not have the port number as an argument of the constructor?
Monday, July 10, 2006
There is no way to set CLR parameters like you are talking about. The only reason this works in Java is because you are invoking the java.exe program directly and passing IT the command line arguments. Since you don't invoke the CLR directly when running a .NET application there is no mechanism for this.
As others have suggested, your only option appears to be to pass the port to the library from a test program. How you do that is up to you.
Monday, July 10, 2006
There are a host of ways you can do something like this. You _can_ get command line parameters passed to an application from a library contrary to what the above poster states, take a look at System.Environment.GetCommandLineArgs(). Another way to do it would be to use an environment variable (e.g. 'set port=9090' from the command shell that you launch the .exe from), and you would use System.Environment.GetEnvironmentVariable() to get the value. You could also write a config section handler and set it in the app config. I'm sure there are other ways to do something like this.
Sunday, July 30, 2006
This topic is archived. No further replies will be accepted.Other recent topics
Powered by FogBugz