SqlHelper Block - Are all of these shared/static methods good?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm hoping that there's something about the underpinnings of the .NET
framework that I don't understand. Something about the SqlHelper appliaction
block, though, kinda creeps me out.

All of its methods are static/shared.

To my understanding, this means that there is a single instance of a given
method. For the purposes of this discussion, lets say its ExecuteDataset.

Lets say that I have a procedure that takes 5 seconds to run and I call that
procedure through ExecuteDataset. The resultant dataset is used in a ASP.NET
Webform we'll call FormX.

It seems to me that if the data method is static, and there's only one
instance of it, there would be a contention issue for that method. So if I
have 20 people accessing that page, there would be 20 simultaneous calls to
that one method, which takes 5 seconds. There would be one person that has
to wait 100 seconds for a response.

So this doesn't sound like a "Best Practice." What am I missing?
 
There's always one "instance" of a method whether it's static or not

The only difference between a static and an instance method it's that
the second one requires a reference to an object ("this" in C# / "Me" in
VB.NET) which is passed as a hidden argument. As long as no static
variables are used inside the static method everything is safe.

If there where 20 simultaneous requests they would be served by twenty
threads and each one would invoke the method "concurrently" and would
execute in parallel so nobody gets to wait 100 secs...As I said before
methods are not instanced and they don't have to be executed in a
serialized fashion.
 
Don't confuse code and data. The code is not instanciated. This is the same
code that runs multiple times with each time its own set of local (that is
private non shared) variables.

Note that the "static" c# keyword that applies to methods has nothing to do
with the VB.NET static keyword (could it be the source of this confusion
?)...

static c# is "shared" in VB.NET. It applies to the method. Inside the
method, variables are still local variables (not static variables in the
VB.NET sense).

Patrice
 
Back
Top