saddy

Hi,

I need to keep in memory a value that the user would have enterred. i don't even know if it is possible

Can you help me



Re: Visual C# General keep in memory

Mattias Sjogren

For how long do you need to keep it in memory Do you mean you want to keep it after your application exits






Re: Visual C# General keep in memory

saddy

yes, exactly, and the user must have the possibility to modify it if he wants. do you see what i want to do




Re: Visual C# General keep in memory

Mark Dawson

Hi,

so you want to persist a value even after the user has closed the application, so that if they open a new instance of the application it can use the same value If so you could write the value to the registry, a file such as an XML file of the App.Config file, that way when the application starts up you can read the value back into memory, is that what you want to do

Mark.






Re: Visual C# General keep in memory

nattylife

serialize it in an xml file (though this might be overkill for a simple number) or just write it to a text file. why does it need to stay in memory after the application closes



Re: Visual C# General keep in memory

saddy

yes, it is exactely what i want to do i will try your solution and will tell if it works.




Re: Visual C# General keep in memory

RizwanSharp

First of all keep in mind, When applicaiton is closed all memory it used is gone. So you cannot keep a reference of that (Atleast not in the modern Languages).

The best thing you can do is ofcourse would be the use of Client Settings of .Net.

Simply create a new key put a value in it and go... You can also add your own Custom types in Client Setting.

To do it, Double Click Settings.setting under Properties in Solution Explorer

I hope you will get what to do next.

When a Key is created simply from your code you can access that in read/write mode using:

global::<namespacename>.Properties.Settings.Default.<KeyName>

After updating the value you can call global::<namespacename>.Properties.Settings.Default.Save();

method to save changes.

Next time when you'll run the program you will be able to access the saved data from it.

Its simple and safe. Registry may cause security exception, can cause complexity same is the case to do it with custom config files.

Best Regards,

Rizwan aka RizwanSharp