Results 1 to 6 of 6

Thread: [RESOLVED] [1.0/1.1] static function

  1. #1

    Thread Starter
    Fanatic Member popskie's Avatar
    Join Date
    Jul 2005
    Location
    In my chair
    Posts
    666

    Resolved [RESOLVED] [1.0/1.1] static function

    Hi,
    Somebody can explain about my doubts in static function. If two users used at the same time. Would be posible the value inside this function can be is the parameter pass by user2?
    ex.
    user1 =Functionname("A","B");
    user2 =Functionname("C","D");


    public static string Functionname(string par1, string par2)
    {
    string concatstring = par1 + par2;
    //code here
    //code here // user2 at this line
    //code here
    //code here
    //code here // user1 at this line . what is the value of concatstring of user1 at this moment?

    return concatstring;




    }

    Thanks
    popskie

  2. #2
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724

    Re: [1.0/1.1] static function

    As long as you're not modifying a single global instance you'll be fine - any concurrent calls will use the parameters (as per your example) as provided.

  3. #3
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: [1.0/1.1] static function

    Its been a while since i've used static methods but from what you wrote, I think its about functions and not the static property of it. When you invoke a method / function call, the only way to the "outside world" is via the parameter and return statement. Everything else is considered as outside. So if for user 1 you call the function

    user1 =Functionname("A","B");

    And use user2 in that same function, then I think you need to change up the code in the function / method.

    Methods are like black boxes. You input something (paramters) and you get an output (return).

    Could you clarify further as to what exactly you want to do?

  4. #4

    Thread Starter
    Fanatic Member popskie's Avatar
    Join Date
    Jul 2005
    Location
    In my chair
    Posts
    666

    Re: [1.0/1.1] static function

    Axion what do you mean for single global variable? It's a static global variable? JBabe my issue here is about concerrency if used a static funtion. If two user simultaneousy access the same function. I have no dout in windows app cause it create another instance but my app now web.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [1.0/1.1] static function

    This has got nothing whatsoever to do with static methods. Two calls to a method will create two sets of local data whether the method is static or not. That means that each call has distinct parameter values and local variables. If a method accesses non-local data, i.e. anything other than its own parameters and local variables, then two calls to that method executing simultaneously can interfere with each other. Again, it makes no difference whether the method is static or not. If a method accesses a static variable, which all non-local variables in a ststic method must be, then absolutely two calls to that method executing simultaneously can interfere.

    I keep saying that to understand OOP you simply have to think about the real world. If there is a single egg carton then putting eggs into that egg carton and taking them out at the same time will interfere. It doesn't matter whether I'm putting them in with one hand and taking them out with the other or I'm putting them in and someone else is taking them out. Either way the carton's never going to get full.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

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