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. Use a static method / class?

Use a static method / class?

Scheduled Pinned Locked Moved C#
databasequestioncsharpasp-netsysadmin
4 Posts 4 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.
  • G Offline
    G Offline
    gmhanna
    wrote on last edited by
    #1

    Hi, I am in the middle of writing an ASP.Net program that will hand off a software key when the Web Server is called. I am receiving information from the caller in a "Query String" and saving it in a common class. After I have saved all the Query Strings, I am calling a Web Service to generate the key, using properties in the common class. If I successfully generate a key, I save the properties in the common class and the key to a SQL database on the server. My question is should I use a static class or should I instantiate a new instance of the class? I'm concerned about the properties getting overlaid by the next caller before the key is generate and the information about the buyer is written to the SQL database. At least hopefully thinking that I will be selling that much software ;) Thank you,

    Glenn

    V L B 3 Replies Last reply
    0
    • G gmhanna

      Hi, I am in the middle of writing an ASP.Net program that will hand off a software key when the Web Server is called. I am receiving information from the caller in a "Query String" and saving it in a common class. After I have saved all the Query Strings, I am calling a Web Service to generate the key, using properties in the common class. If I successfully generate a key, I save the properties in the common class and the key to a SQL database on the server. My question is should I use a static class or should I instantiate a new instance of the class? I'm concerned about the properties getting overlaid by the next caller before the key is generate and the information about the buyer is written to the SQL database. At least hopefully thinking that I will be selling that much software ;) Thank you,

      Glenn

      V Offline
      V Offline
      V 0
      wrote on last edited by
      #2

      gmhanna wrote:

      I'm concerned about the properties getting overlaid by the next caller

      That would also have been my concern, so I think you should stick with normal classes/objects.

      V.

      1 Reply Last reply
      0
      • G gmhanna

        Hi, I am in the middle of writing an ASP.Net program that will hand off a software key when the Web Server is called. I am receiving information from the caller in a "Query String" and saving it in a common class. After I have saved all the Query Strings, I am calling a Web Service to generate the key, using properties in the common class. If I successfully generate a key, I save the properties in the common class and the key to a SQL database on the server. My question is should I use a static class or should I instantiate a new instance of the class? I'm concerned about the properties getting overlaid by the next caller before the key is generate and the information about the buyer is written to the SQL database. At least hopefully thinking that I will be selling that much software ;) Thank you,

        Glenn

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

        You can use a thread-safe Singleton class like this:

        public sealed class Singleton {
        private static Singleton _instance = null;
        private static readonly object singletonLock = new object();

        private Singleton() {}
        
        public static Singleton Instance {
            get {
                lock (singletonLock) {
                    if (\_instance == null) {
                        \_instance = new Singleton();
                    }
                    return \_instance;
                }
            }
        }
        

        }

        "Don't confuse experts with facts" - Eric_V

        1 Reply Last reply
        0
        • G gmhanna

          Hi, I am in the middle of writing an ASP.Net program that will hand off a software key when the Web Server is called. I am receiving information from the caller in a "Query String" and saving it in a common class. After I have saved all the Query Strings, I am calling a Web Service to generate the key, using properties in the common class. If I successfully generate a key, I save the properties in the common class and the key to a SQL database on the server. My question is should I use a static class or should I instantiate a new instance of the class? I'm concerned about the properties getting overlaid by the next caller before the key is generate and the information about the buyer is written to the SQL database. At least hopefully thinking that I will be selling that much software ;) Thank you,

          Glenn

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

          This seems like something that should go in the session, if it is supposed to persist for more than one page hit.

          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