|
-
Jul 28th, 2011, 09:07 AM
#1
Thread Starter
Frenzied Member
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 
-
Jul 28th, 2011, 09:28 AM
#2
Thread Starter
Frenzied Member
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 
-
Jul 29th, 2011, 01:34 AM
#3
Re: Static methods in asp.net
Can you confirm exactly what you mean by "safe"? What context are you referring to?
Gary
-
Jul 29th, 2011, 05:21 AM
#4
Thread Starter
Frenzied Member
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 
-
Jul 29th, 2011, 02:15 PM
#5
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
-
Jul 29th, 2011, 06:33 PM
#6
Thread Starter
Frenzied Member
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 
-
Jul 30th, 2011, 08:32 AM
#7
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
-
Jul 30th, 2011, 08:36 AM
#8
Thread Starter
Frenzied Member
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 
-
Jul 30th, 2011, 08:50 AM
#9
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
-
Jul 30th, 2011, 08:53 AM
#10
Thread Starter
Frenzied Member
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 
-
Jul 30th, 2011, 08:55 AM
#11
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|