none
Maintain service state after system reboot RRS feed

  • Question

  • Hi to everyone.

    I created a windows service in c# with automatic restart option.  I want to maintain the state of the service after windows reboot.  Here I'm referring state as the values of service variables and memory information.  One possible way to achieve this is, by storing the information in file system or database.  Is there any other possibility to achieve this by storing the data in memory which will not vanish during system reboot.


    MIB

    • Moved by Sabah ShariqMVP Thursday, April 27, 2017 2:46 PM Moved From Visual C#
    Wednesday, April 26, 2017 1:21 PM

All replies

  • If you need to maintain state across runs of your service (including stop and start) then you'll have to store the data outside of memory. Anything store in memory is going to get wiped when the service stops. You can use a local database if you have a lot of data or a simple binary file if it is small sets of data. Technically you could also store data in the registry but that is probably not a good choice in your situation.

    Michael Taylor
    http://www.michaeltaylorp3.net

    Thursday, April 27, 2017 2:32 PM
    Moderator
  • >> Is there any other possibility to achieve this by storing the data in memory which will not vanish during system reboot

    No, it is impossible. Data in memory will be released after system reboot.

    I suggest you store them in file or database.


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, April 28, 2017 5:31 AM