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. The Lounge
  3. What technique do you use to persist state?

What technique do you use to persist state?

Scheduled Pinned Locked Moved The Lounge
csharpquestionphprubycss
40 Posts 25 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.
  • F Forogar

    Quote:

    // Silently handle exceptions for when we add state items that aren't part of the state file until we

    FTFY

    - Life in the fast lane is only fun if you live in a country with no speed limits. - Of all the things I have lost, it is my mind that I miss the most. - I vaguely remember having a good memory...

    M Offline
    M Offline
    Marc Clifton
    wrote on last edited by
    #22

    Forogar wrote:

    FTFY

    Why thank you! Correctness in comments is very important! Marc

    Latest Article: C# and Ruby Classes: A Deep Dive
    My Blog

    1 Reply Last reply
    0
    • M Marc Clifton

      No, not a programming question, and no, not a "recover from a Friday drinking binge" question. Just curious, what different techniques people use (specifically for WinForm apps). Do you roll your own persistence class? If you're a .NET developer, do you use ApplicationSettingsBase[^] ? I'm also curious, if you develop client/server apps, if you store your app's state information locally or in a database so that your user can use any client machine and the UI is configured to their preferences ? And yes, I'm talking about UI things, such as last window size and location, but also more interesting things such as what columns the user selected to be visible on a grid, what display order, what sort order, etc. Same with, say, a tree control - what nodes were expanded and what nodes weren't? Plus things like "exit without asking" info, and so forth. Heck, do you even save the user's preferences / state of the UI? Marc

      Latest Article: C# and Ruby Classes: A Deep Dive
      My Blog

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #23

      Marc Clifton wrote:

      If you're a .NET developer, do you use ApplicationSettingsBase[^] ?

      Yes, get's used from time to time; there's a wizard integrated into the IDE to manipulate the settings-file, it's defaults, and one can very easily bind to a property and forget about it.

      Marc Clifton wrote:

      if you develop client/server apps, if you store your app's state information locally or in a database so that your user can use any client machine and the UI is configured to their preferences ?

      The apps state-information is not stored; only preferences, on user and application-scope (local and global). I've tried to save the complete state once (including undo/redo stack) and have the app restore to that state - it just confuses the users.

      Marc Clifton wrote:

      And yes, I'm talking about UI things, such as last window size and location

      Hence the difference between "local" and "global" user-settings. Some things roam, others don't. The form-size doesn't roam, since my monitors have different sizes at different work-locations.

      Marc Clifton wrote:

      Same with, say, a tree control - what nodes were expanded and what nodes weren't?

      No, not ever. How often do you need to be at that exact place in the tree? If very often, make a shortcut for the user. The reasoning is simlpe; you don't want to wait until the "Windows Explorer" loaded the entire tree, if you can simply click a hyperlink.

      Marc Clifton wrote:

      Plus things like "exit without asking" info, and so forth.

      The question does not even exist. There's only a warning if something is dirty, but I'm not going to ask the user whether he knows what he/she is doing on every action.

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

      M 1 Reply Last reply
      0
      • M Marc Clifton

        Klaus-Werner Konrad wrote:

        factory (our) settings -> company settings -> user settings

        Nice! Marc

        Latest Article: C# and Ruby Classes: A Deep Dive
        My Blog

        K Offline
        K Offline
        Klaus Werner Konrad
        wrote on last edited by
        #24

        Thanks ! I should add, there is a Y/N field in the table that says 'station specific', so I can use one table for user AND station dependant settings, such as directories.

        1 Reply Last reply
        0
        • M Marc Clifton

          No, not a programming question, and no, not a "recover from a Friday drinking binge" question. Just curious, what different techniques people use (specifically for WinForm apps). Do you roll your own persistence class? If you're a .NET developer, do you use ApplicationSettingsBase[^] ? I'm also curious, if you develop client/server apps, if you store your app's state information locally or in a database so that your user can use any client machine and the UI is configured to their preferences ? And yes, I'm talking about UI things, such as last window size and location, but also more interesting things such as what columns the user selected to be visible on a grid, what display order, what sort order, etc. Same with, say, a tree control - what nodes were expanded and what nodes weren't? Plus things like "exit without asking" info, and so forth. Heck, do you even save the user's preferences / state of the UI? Marc

          Latest Article: C# and Ruby Classes: A Deep Dive
          My Blog

          S Offline
          S Offline
          S Houghtelin
          wrote on last edited by
          #25
          this.WindowState = FormWindowState.Maximized;
          this.MinimumSize = this.Size;
          this.MaximumSize = this.Size;
          

          Generally I use the an application config file for persistant settings.

          It was broke, so I fixed it.

          1 Reply Last reply
          0
          • M Marc Clifton

            No, not a programming question, and no, not a "recover from a Friday drinking binge" question. Just curious, what different techniques people use (specifically for WinForm apps). Do you roll your own persistence class? If you're a .NET developer, do you use ApplicationSettingsBase[^] ? I'm also curious, if you develop client/server apps, if you store your app's state information locally or in a database so that your user can use any client machine and the UI is configured to their preferences ? And yes, I'm talking about UI things, such as last window size and location, but also more interesting things such as what columns the user selected to be visible on a grid, what display order, what sort order, etc. Same with, say, a tree control - what nodes were expanded and what nodes weren't? Plus things like "exit without asking" info, and so forth. Heck, do you even save the user's preferences / state of the UI? Marc

            Latest Article: C# and Ruby Classes: A Deep Dive
            My Blog

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #26

            Users? What are those? I use XML: XmlNode[^]

            1 Reply Last reply
            0
            • L Lost User

              Marc Clifton wrote:

              If you're a .NET developer, do you use ApplicationSettingsBase[^] ?

              Yes, get's used from time to time; there's a wizard integrated into the IDE to manipulate the settings-file, it's defaults, and one can very easily bind to a property and forget about it.

              Marc Clifton wrote:

              if you develop client/server apps, if you store your app's state information locally or in a database so that your user can use any client machine and the UI is configured to their preferences ?

              The apps state-information is not stored; only preferences, on user and application-scope (local and global). I've tried to save the complete state once (including undo/redo stack) and have the app restore to that state - it just confuses the users.

              Marc Clifton wrote:

              And yes, I'm talking about UI things, such as last window size and location

              Hence the difference between "local" and "global" user-settings. Some things roam, others don't. The form-size doesn't roam, since my monitors have different sizes at different work-locations.

              Marc Clifton wrote:

              Same with, say, a tree control - what nodes were expanded and what nodes weren't?

              No, not ever. How often do you need to be at that exact place in the tree? If very often, make a shortcut for the user. The reasoning is simlpe; you don't want to wait until the "Windows Explorer" loaded the entire tree, if you can simply click a hyperlink.

              Marc Clifton wrote:

              Plus things like "exit without asking" info, and so forth.

              The question does not even exist. There's only a warning if something is dirty, but I'm not going to ask the user whether he knows what he/she is doing on every action.

              Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

              M Offline
              M Offline
              Marc Clifton
              wrote on last edited by
              #27

              Eddy Vluggen wrote:

              you don't want to wait until the "Windows Explorer" loaded the entire tree,

              I meant trees like, "to do" lists or some other hierarchical information.

              Eddy Vluggen wrote:

              on user and application-scope (local and global)

              That makes sense. Marc

              Latest Article: C# and Ruby Classes: A Deep Dive
              My Blog

              1 Reply Last reply
              0
              • M Marc Clifton

                Ennis Ray Lynch, Jr. wrote:

                If Windows and Firefox can't manage to get UI saving settings right why even bother?

                Yes, that's one of the issues I think is important to deal with, as I've often had apps open areas that are no longer visible because I've removed a monitor. Marc

                Latest Article: C# and Ruby Classes: A Deep Dive
                My Blog

                RaviBeeR Offline
                RaviBeeR Offline
                RaviBee
                wrote on last edited by
                #28

                IMHO, this is a generic problem: i.e. restoring potentially invalid state.  Whenever I restore state (almost always from an editable XML file), my code validates and auto-corrects the data being read.  Other examples of this are selecting a tree node that may no longer exist, etc.  The bottom line is, it's the developer's responsibility to handle all possible use cases. All this takes additional work and time.  And your users will love you for it. /ravi

                My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                1 Reply Last reply
                0
                • M Marc Clifton

                  No, not a programming question, and no, not a "recover from a Friday drinking binge" question. Just curious, what different techniques people use (specifically for WinForm apps). Do you roll your own persistence class? If you're a .NET developer, do you use ApplicationSettingsBase[^] ? I'm also curious, if you develop client/server apps, if you store your app's state information locally or in a database so that your user can use any client machine and the UI is configured to their preferences ? And yes, I'm talking about UI things, such as last window size and location, but also more interesting things such as what columns the user selected to be visible on a grid, what display order, what sort order, etc. Same with, say, a tree control - what nodes were expanded and what nodes weren't? Plus things like "exit without asking" info, and so forth. Heck, do you even save the user's preferences / state of the UI? Marc

                  Latest Article: C# and Ruby Classes: A Deep Dive
                  My Blog

                  B Offline
                  B Offline
                  BobJanova
                  wrote on last edited by
                  #29

                  I typically save a file in the working directory, which allows the user to set up different shortcuts with different preferences if they want, and it makes the app portable as nothing is stored in system folders (or the registry etc) so you can put it on a USB stick. I put default configuration settings into the app as a resource so I can use the same reader to load it.

                  1 Reply Last reply
                  0
                  • M Marc Clifton

                    No, not a programming question, and no, not a "recover from a Friday drinking binge" question. Just curious, what different techniques people use (specifically for WinForm apps). Do you roll your own persistence class? If you're a .NET developer, do you use ApplicationSettingsBase[^] ? I'm also curious, if you develop client/server apps, if you store your app's state information locally or in a database so that your user can use any client machine and the UI is configured to their preferences ? And yes, I'm talking about UI things, such as last window size and location, but also more interesting things such as what columns the user selected to be visible on a grid, what display order, what sort order, etc. Same with, say, a tree control - what nodes were expanded and what nodes weren't? Plus things like "exit without asking" info, and so forth. Heck, do you even save the user's preferences / state of the UI? Marc

                    Latest Article: C# and Ruby Classes: A Deep Dive
                    My Blog

                    G Offline
                    G Offline
                    Gary Wheeler
                    wrote on last edited by
                    #30

                    My application is a bit different. We run a printing press and related equipment. In that case, there aren't any 'user-specific' data to be persisted. At one time we would have used HKEY_LOCAL_MACHINE in the registry and called it a day, or stored a file with our application. Under Win7, none of that works. Our current solution is a group of XML files stored in the folder returned by SHGetKnownFolderPath(FOLDERID_ProgramData)[^]. I keep waiting for some moron to suggest we store settings data in the 'cloud' even though our machines never have an Internet connection...

                    Software Zen: delete this;

                    K 1 Reply Last reply
                    0
                    • M Marc Clifton

                      No, not a programming question, and no, not a "recover from a Friday drinking binge" question. Just curious, what different techniques people use (specifically for WinForm apps). Do you roll your own persistence class? If you're a .NET developer, do you use ApplicationSettingsBase[^] ? I'm also curious, if you develop client/server apps, if you store your app's state information locally or in a database so that your user can use any client machine and the UI is configured to their preferences ? And yes, I'm talking about UI things, such as last window size and location, but also more interesting things such as what columns the user selected to be visible on a grid, what display order, what sort order, etc. Same with, say, a tree control - what nodes were expanded and what nodes weren't? Plus things like "exit without asking" info, and so forth. Heck, do you even save the user's preferences / state of the UI? Marc

                      Latest Article: C# and Ruby Classes: A Deep Dive
                      My Blog

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #31

                      I the app I'm working on at the moment there s some I the db, som in the app config and soe in a text file cleverly renamed as a dell so the user doesn't try to edit it!!!

                      MVVM# - See how I did MVVM my way ___________________________________________ Man, you're a god. - walterhevedeich 26/05/2011 .\\axxx (That's an 'M')

                      1 Reply Last reply
                      0
                      • M Marc Clifton

                        No, not a programming question, and no, not a "recover from a Friday drinking binge" question. Just curious, what different techniques people use (specifically for WinForm apps). Do you roll your own persistence class? If you're a .NET developer, do you use ApplicationSettingsBase[^] ? I'm also curious, if you develop client/server apps, if you store your app's state information locally or in a database so that your user can use any client machine and the UI is configured to their preferences ? And yes, I'm talking about UI things, such as last window size and location, but also more interesting things such as what columns the user selected to be visible on a grid, what display order, what sort order, etc. Same with, say, a tree control - what nodes were expanded and what nodes weren't? Plus things like "exit without asking" info, and so forth. Heck, do you even save the user's preferences / state of the UI? Marc

                        Latest Article: C# and Ruby Classes: A Deep Dive
                        My Blog

                        M Offline
                        M Offline
                        Mycroft Holmes
                        wrote on last edited by
                        #32

                        XML file, even wrote an article about it way back. I rarely needed the persistence and now I use Silverlight and they don't get a choice.

                        Never underestimate the power of human stupidity RAH

                        1 Reply Last reply
                        0
                        • C c2423

                          I like to randomise it on every load to keep people on their toes. Seriously though, where I need to I roll my own - XML file normally to save the data, then my own class on top so that I can make sure it's strongly typed. Probably not the most efficient possible, but if I can add XML comments to my settings class the intellisense saves me a load of frustration trying to remember stuff.

                          S Offline
                          S Offline
                          S Douglas
                          wrote on last edited by
                          #33

                          c2423 wrote:

                          I like to randomise it.

                          Must work for Oracle


                          Common sense is admitting there is cause and effect and that you can exert some control over what you understand.

                          1 Reply Last reply
                          0
                          • M Marc Clifton

                            No, not a programming question, and no, not a "recover from a Friday drinking binge" question. Just curious, what different techniques people use (specifically for WinForm apps). Do you roll your own persistence class? If you're a .NET developer, do you use ApplicationSettingsBase[^] ? I'm also curious, if you develop client/server apps, if you store your app's state information locally or in a database so that your user can use any client machine and the UI is configured to their preferences ? And yes, I'm talking about UI things, such as last window size and location, but also more interesting things such as what columns the user selected to be visible on a grid, what display order, what sort order, etc. Same with, say, a tree control - what nodes were expanded and what nodes weren't? Plus things like "exit without asking" info, and so forth. Heck, do you even save the user's preferences / state of the UI? Marc

                            Latest Article: C# and Ruby Classes: A Deep Dive
                            My Blog

                            B Offline
                            B Offline
                            Brady Kelly
                            wrote on last edited by
                            #34

                            Most applications use a data store for business data anyway. Why not use a partition of this data store for application state data?

                            M 1 Reply Last reply
                            0
                            • B Brady Kelly

                              Most applications use a data store for business data anyway. Why not use a partition of this data store for application state data?

                              M Offline
                              M Offline
                              Marc Clifton
                              wrote on last edited by
                              #35

                              Brady Kelly wrote:

                              Why not use a partition of this data store for application state data?

                              Of course, but I was curious if people actually do that, or store config info elsewhere. Marc

                              Latest Article: C# and Ruby Classes: A Deep Dive
                              My Blog

                              1 Reply Last reply
                              0
                              • M Marc Clifton

                                No, not a programming question, and no, not a "recover from a Friday drinking binge" question. Just curious, what different techniques people use (specifically for WinForm apps). Do you roll your own persistence class? If you're a .NET developer, do you use ApplicationSettingsBase[^] ? I'm also curious, if you develop client/server apps, if you store your app's state information locally or in a database so that your user can use any client machine and the UI is configured to their preferences ? And yes, I'm talking about UI things, such as last window size and location, but also more interesting things such as what columns the user selected to be visible on a grid, what display order, what sort order, etc. Same with, say, a tree control - what nodes were expanded and what nodes weren't? Plus things like "exit without asking" info, and so forth. Heck, do you even save the user's preferences / state of the UI? Marc

                                Latest Article: C# and Ruby Classes: A Deep Dive
                                My Blog

                                R Offline
                                R Offline
                                RafagaX
                                wrote on last edited by
                                #36

                                I use ApplicationSettingsBase when the configuration only applies to one application and one user, otherwise I may use a custom XML configuration file somewhere in a public folder, or use a database.

                                CEO at: - Rafaga Systems - Para Facturas - Modern Components for the moment...

                                1 Reply Last reply
                                0
                                • M Marc Clifton

                                  No, not a programming question, and no, not a "recover from a Friday drinking binge" question. Just curious, what different techniques people use (specifically for WinForm apps). Do you roll your own persistence class? If you're a .NET developer, do you use ApplicationSettingsBase[^] ? I'm also curious, if you develop client/server apps, if you store your app's state information locally or in a database so that your user can use any client machine and the UI is configured to their preferences ? And yes, I'm talking about UI things, such as last window size and location, but also more interesting things such as what columns the user selected to be visible on a grid, what display order, what sort order, etc. Same with, say, a tree control - what nodes were expanded and what nodes weren't? Plus things like "exit without asking" info, and so forth. Heck, do you even save the user's preferences / state of the UI? Marc

                                  Latest Article: C# and Ruby Classes: A Deep Dive
                                  My Blog

                                  M Offline
                                  M Offline
                                  Member_5893260
                                  wrote on last edited by
                                  #37

                                  It depends. In some applications it makes sense to use an XML file; in others, I use the registry; in others a database. In terms of what to save there: again, that depends on the applications. In some applications, form state is an integral part of how a document is displayed; in others it's unimportant. The same is true of behavioural settings. For Client/Server stuff, there usually ends up being a mix of techniques: things you want to persist across multiple installations of a product (by user) get stored in the database; stuff which has more to do with how the application looks on the screen of a specific machine get stored in the registry. I think it's all about common sense -- ask yourself questions like, "How annoying would it be if [this setting] did[n't] persist across different installation instances?".

                                  1 Reply Last reply
                                  0
                                  • E Ennis Ray Lynch Jr

                                    Back when I was a teenager, I thought saving UI State was all the rage but I soon gave it up. The massive amount of code required to store and manage it and make it all perfect just wasn't worth it. Heck, even today, I have a problem when I load firefox at home. You see I have a laptop hooked up to another monitor. However, that monitor is also wired to another machine. When the other machine is on, Windows on the laptop works fine but when I open something that was previously opened on the second monitor guess where it opens? If Windows and Firefox can't manage to get UI saving settings right why even bother? Plus, if you make an infinitely configurable UI, power users will complain that they can't configure X and that is so obvious or worse an upgrade will wipe their settings and lose you a customer. So, long story short, only save the bare essentials that make the app usable. The rest, don't make configurable unless they ask.

                                    Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. "And they, since they Were not the one dead, turned to their affairs" -- Robert Frost "All users always want Excel" --Ennis Lynch

                                    K Offline
                                    K Offline
                                    Kabwla Phone
                                    wrote on last edited by
                                    #38

                                    Hi, I have been a developer for many years now, and I support this message to the fullest. So should YOU! Seriously, settings are such a hassle. The 'Appconfig' likes to forget them. If you roll your own you have to be backward compatible. Even VS has a 'reset to defaults button' for the interface because it can get stuck in a bad layout you can not manually correct anymore. If you provide too many options your application becomes 'too difficult' Fortunately I was able to convince my coworkers of this. Our application remembers the sizes of the screens, when a screen is shown, it checks if the position is a valid desktop position (making multi-monitor compatible even if you remove a monitor). That's it. Whenever a customer ask for more setting, we say: Tell us exactly what settings you want. For which screens? How should remember them? Is it ok to break it with future changes. But before you do this, remember that each setting cost 1 hour to develop, 1 hour to deploy, 1 hour to test. Plus the square root (in hours) of all settings combined for additional testing where settings may interfere with each other. Then multiply that with out hourly wage and ask yourself this question: "Do you really want that setting?" Maybe, one day, one of our clients will say yes... Then we'll slap them with a 200% 'we really do not want to do this' bonus fee.

                                    1 Reply Last reply
                                    0
                                    • G Gary Wheeler

                                      My application is a bit different. We run a printing press and related equipment. In that case, there aren't any 'user-specific' data to be persisted. At one time we would have used HKEY_LOCAL_MACHINE in the registry and called it a day, or stored a file with our application. Under Win7, none of that works. Our current solution is a group of XML files stored in the folder returned by SHGetKnownFolderPath(FOLDERID_ProgramData)[^]. I keep waiting for some moron to suggest we store settings data in the 'cloud' even though our machines never have an Internet connection...

                                      Software Zen: delete this;

                                      K Offline
                                      K Offline
                                      Kabwla Phone
                                      wrote on last edited by
                                      #39

                                      Store it in the cloud! The cloud is magic. It does everything but the dishes! X|

                                      1 Reply Last reply
                                      0
                                      • M Marc Clifton

                                        No, not a programming question, and no, not a "recover from a Friday drinking binge" question. Just curious, what different techniques people use (specifically for WinForm apps). Do you roll your own persistence class? If you're a .NET developer, do you use ApplicationSettingsBase[^] ? I'm also curious, if you develop client/server apps, if you store your app's state information locally or in a database so that your user can use any client machine and the UI is configured to their preferences ? And yes, I'm talking about UI things, such as last window size and location, but also more interesting things such as what columns the user selected to be visible on a grid, what display order, what sort order, etc. Same with, say, a tree control - what nodes were expanded and what nodes weren't? Plus things like "exit without asking" info, and so forth. Heck, do you even save the user's preferences / state of the UI? Marc

                                        Latest Article: C# and Ruby Classes: A Deep Dive
                                        My Blog

                                        M Offline
                                        M Offline
                                        Michael Kingsford Gray
                                        wrote on last edited by
                                        #40

                                        SQL Server

                                        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