Click to See Complete Forum and Search --> : [RESOLVED] [1.0/1.1] static function
popskie
Feb 23rd, 2007, 03:34 AM
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
axion_sa
Feb 23rd, 2007, 11:08 AM
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.
JenniferBabe
Feb 23rd, 2007, 11:15 AM
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?
popskie
Feb 25th, 2007, 07:55 PM
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.
jmcilhinney
Feb 25th, 2007, 08:35 PM
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.
popskie
Feb 25th, 2007, 09:06 PM
Loud and clear JM.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.