Never Use Static Methods in ASP.NET?

B

bradwiseathome

I think I learned somewhere that you should never use classes with
static methods that use ADO.NET inside an ASP.NET app because there is
a danger with thread locks. Is that true for Framework 1.1?

Thanks.
 
J

Jon Skeet [C# MVP]

I think I learned somewhere that you should never use classes with
static methods that use ADO.NET inside an ASP.NET app because there is
a danger with thread locks. Is that true for Framework 1.1?

There's nothing particularly special about static methods in this
respect. If you have a potential deadlock in your code, of course,
that's a problem - but that's not really to do with static methods.
 
B

Bruce Wood

Static data members (fields), maybe, but a static method may use
nothing but the stack, and so be perfectly thread-safe in all contexts.
 
K

Kevin Spencer

I think I learned somewhere that you should never use classes with
static methods that use ADO.NET inside an ASP.NET app because there is
a danger with thread locks. Is that true for Framework 1.1?

It would be better to learn what static methods *are* than to take anything
you are told at face value.

This should help:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfStaticPG.asp

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top