Results 1 to 11 of 11

Thread: Static methods in asp.net

  1. #1

    Thread Starter
    Frenzied Member avrail's Avatar
    Join Date
    Mar 2006
    Location
    Egypt, Cairo
    Posts
    1,221

    Static methods in asp.net

    hay,

    i understand the problem of the static variable inside a class in the web application,

    now i try to create a simple class to deal with SQL Server for example,
    so i created Static Method inside this class,

    this static method used in insert, update and delete from database,
    i wounder if this is safe, and there is no problems will appear ?
    You Don't Have to Rate Me.
    I'm Not a Civilized Man I'm the Civilization it self
    White or Black, Living or Dieing and 0 or 1 that's MY life
    iam an Object in Object Oriented Life
    my blog : http://refateid.blogspot.com/
    twitter :@avrail
    010011000111010101110110001000000100110101111001001000000101000001100011

  2. #2

    Thread Starter
    Frenzied Member avrail's Avatar
    Join Date
    Mar 2006
    Location
    Egypt, Cairo
    Posts
    1,221

    Re: Static methods in asp.net

    now, if it is not safe, so how could i use JQuery Ajax and the server side,
    if the only way to use webMethod is to name it as static :S
    You Don't Have to Rate Me.
    I'm Not a Civilized Man I'm the Civilization it self
    White or Black, Living or Dieing and 0 or 1 that's MY life
    iam an Object in Object Oriented Life
    my blog : http://refateid.blogspot.com/
    twitter :@avrail
    010011000111010101110110001000000100110101111001001000000101000001100011

  3. #3
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Static methods in asp.net

    Can you confirm exactly what you mean by "safe"? What context are you referring to?

    Gary

  4. #4

    Thread Starter
    Frenzied Member avrail's Avatar
    Join Date
    Mar 2006
    Location
    Egypt, Cairo
    Posts
    1,221

    Re: Static methods in asp.net

    well, when 2 clients called the static method to execute a sql statement @ the same time,
    are there any problem @ this time ?

    for example client 1 sql statement is " select * from login"
    client 2 sql statement is "select * from login where login id = 1"

    is there is a chance that client 2 get the result of client 1?
    i know i didn't explain it well
    i wish you understand me
    Last edited by avrail; Jul 29th, 2011 at 05:28 AM.
    You Don't Have to Rate Me.
    I'm Not a Civilized Man I'm the Civilization it self
    White or Black, Living or Dieing and 0 or 1 that's MY life
    iam an Object in Object Oriented Life
    my blog : http://refateid.blogspot.com/
    twitter :@avrail
    010011000111010101110110001000000100110101111001001000000101000001100011

  5. #5
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Static methods in asp.net

    Hello,

    What I think you are referring to is known as concurrency, and you can read more about this here:

    http://www.15seconds.com/issue/030604.htm

    There is a chance, if you are using shared resources that you can run into issues where two threads are trying to access the same resources. In order to guard against this you can use techniques such as "lock" to block one thread until the other one has completed processing.

    Gary

  6. #6

    Thread Starter
    Frenzied Member avrail's Avatar
    Join Date
    Mar 2006
    Location
    Egypt, Cairo
    Posts
    1,221

    Re: Static methods in asp.net

    no that's not what i mean
    i mean when i use static methods in asp.net, the method work per user or per application "like static variables"
    i hope i clear what i mean
    You Don't Have to Rate Me.
    I'm Not a Civilized Man I'm the Civilization it self
    White or Black, Living or Dieing and 0 or 1 that's MY life
    iam an Object in Object Oriented Life
    my blog : http://refateid.blogspot.com/
    twitter :@avrail
    010011000111010101110110001000000100110101111001001000000101000001100011

  7. #7
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Static methods in asp.net

    Hello,

    No, I am not sure that I understand what you are getting at.

    If you declare a method as static, it means that the method refers to a single location and type instead of an instance of that type that was allocated on the managed heap. It has nothing really to do with users.

    Gary

  8. #8

    Thread Starter
    Frenzied Member avrail's Avatar
    Join Date
    Mar 2006
    Location
    Egypt, Cairo
    Posts
    1,221

    Re: Static methods in asp.net

    so if i 2 users called this method, there will be no interference of data ?
    You Don't Have to Rate Me.
    I'm Not a Civilized Man I'm the Civilization it self
    White or Black, Living or Dieing and 0 or 1 that's MY life
    iam an Object in Object Oriented Life
    my blog : http://refateid.blogspot.com/
    twitter :@avrail
    010011000111010101110110001000000100110101111001001000000101000001100011

  9. #9
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Static methods in asp.net

    No, that is not what I am saying.

    A static method does NOT prevent the situation that you are describing.

    If you are trying to prevent issues with concurrency, then you need to look into doing it properly.

    Gary

  10. #10

    Thread Starter
    Frenzied Member avrail's Avatar
    Join Date
    Mar 2006
    Location
    Egypt, Cairo
    Posts
    1,221

    Re: Static methods in asp.net

    i am so sorry Gary
    so what is the big use for the Static methods ?
    You Don't Have to Rate Me.
    I'm Not a Civilized Man I'm the Civilization it self
    White or Black, Living or Dieing and 0 or 1 that's MY life
    iam an Object in Object Oriented Life
    my blog : http://refateid.blogspot.com/
    twitter :@avrail
    010011000111010101110110001000000100110101111001001000000101000001100011

  11. #11
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Static methods in asp.net

    As I have already mentioned, when you declare a method of a class as Static you can have access to that method without having to create an instance of that class (or more specifically, that type).

    I would suggest that you take a look here:

    http://msdn.microsoft.com/en-us/libr...(v=vs.80).aspx

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width