Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Best way to save state (Windows Forms)

Best way to save state (Windows Forms)

Scheduled Pinned Locked Moved C#
winformswindows-adminxmltutorialquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    profoundwhispers
    wrote on last edited by
    #1

    Every 30 seconds or so, I need my application to persist state, just in case the power goes off or something like that. What's the best method based upon this time frame? For example: - Save to an XML configuration file. - Save to registry. - Save to binary file (serialize object?) - Something better? Thank you. Sammy "A good friend, is like a good book: the inside is better than the cover..."

    H D 2 Replies Last reply
    0
    • P profoundwhispers

      Every 30 seconds or so, I need my application to persist state, just in case the power goes off or something like that. What's the best method based upon this time frame? For example: - Save to an XML configuration file. - Save to registry. - Save to binary file (serialize object?) - Something better? Thank you. Sammy "A good friend, is like a good book: the inside is better than the cover..."

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      Don't save to the registry with .NET applications. It's not a good practice for many reasons, especially deployment issues. Other than that, save to whatever file format you want. Binary serialiation is faster than XML, but XML gives you the ability to easily customize the state while the program is not running. One other way - albeit more difficult - would be to implement a custom BindingManagerBase derivative that uses a file as a backing store and bind the properties of controls you want persisted. When they change, the binding manager is updated and your derivative class could save state immediately. This way, you don't have to poll and don't have to keep a timer, which is relatively inefficient since the state of your application might not have changed. See the documentation for the BindingManagerBase and Control.DataBindings in the .NET Framework SDK for more information.

      Microsoft MVP, Visual C# My Articles

      1 Reply Last reply
      0
      • P profoundwhispers

        Every 30 seconds or so, I need my application to persist state, just in case the power goes off or something like that. What's the best method based upon this time frame? For example: - Save to an XML configuration file. - Save to registry. - Save to binary file (serialize object?) - Something better? Thank you. Sammy "A good friend, is like a good book: the inside is better than the cover..."

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        Another consideration for your design should be: What happens if the power goes out WHILE the state is being saved? If your app is that critical, you might want to consider a UPS and monitor that for a power outage so your app can save it's state one last time before the power REALLY goes out. RageInTheMachine9532

        P 1 Reply Last reply
        0
        • D Dave Kreskowiak

          Another consideration for your design should be: What happens if the power goes out WHILE the state is being saved? If your app is that critical, you might want to consider a UPS and monitor that for a power outage so your app can save it's state one last time before the power REALLY goes out. RageInTheMachine9532

          P Offline
          P Offline
          profoundwhispers
          wrote on last edited by
          #4

          Okay, it's not THAT critical :) Thanks! Sammy "A good friend, is like a good book: the inside is better than the cover..."

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups