Rhys Drury
Rhys Drury

Reputation: 315

Setting ID Number for each instance of a program running

Basically, what I need to do is set a number for each instance of my program running, so I can tell which program is doing what.

I am simulating a Petrol Pump App and I need to have it so each time it runs the first running program will always be pump 1, then 2 until 6. The finished product will have 6 instances of the program running that will always be labelled 1-6 ( no random generation)

I think it's to do with the app config file, but I'm really not sure how I would go about it. Any ideas?

Sorry it's vague but It's hard to describe the problem. thanks in advance

Edit: The idea is that I can use this unique I.D to send to the Point of Sale to identify the pump being used

Upvotes: 0

Views: 149

Answers (3)

Rhys Drury
Rhys Drury

Reputation: 315

What I did instead, is just make an initialisation form, and let the user just choose which pump it was when the program is first run. This way I could use a WCF service to dynamically generate the amount of pumps created . It doesn't change the app config so doesn't exactly answer my question, but it was enough to get it working how I needed it to.

Upvotes: 0

just put the number as a app setting in app.config http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.appsettings.aspx

from the article

add settings like this

    <appSettings>
  <add key="IdValue" value="1" />

and get them in your code like this

     var appSettings = ConfigurationManager.AppSettings;
     var id = appSettings["IdValue"];

Upvotes: 1

Kixoka
Kixoka

Reputation: 1161

You could have the app check the config for the "Next Number". Then once the app loads have that app do nextNumber + 1 and update the config file. You may also want to have a stack variable in the config file so you can keep track of the numbers (eg: "1,2,3,4,5,6") if you delete one the reset the next number - 1 and remove the number from the stack variable.... so you basically track the number of instances and the their labels... so you dont have 2 pumps with the same number.

Upvotes: 1

Related Questions