Pete_ch
Pete_ch

Reputation: 1321

are there potential pitfalls to using static methods in a web application (.net)?

From the web app, calls are made to a web service that in turn makes calls to a few static helper classes for filtering and sorting data - trying to think ahead if I will have unexpected behavior with multiple users

Upvotes: 3

Views: 719

Answers (3)

Eric J.
Eric J.

Reputation: 150228

Make sure your static methods are thread-safe.

Thread safety fundamentally deals with ensuring that two threads don't access a shared resource in a conflicting manner.

There's a great overview on Wikipedia.

The best tutorial I have ever found about threading in the .NET environment is by Joe Albahari.

Upvotes: 3

Jeff Foster
Jeff Foster

Reputation: 44746

No, as long as those methods don't share access any shared resources. This could be:

  • A file on disk
  • Some static data
  • Another external resource

You just have to be sure that you aren't inadvertently sharing any resources / static data.

Upvotes: 2

aqwert
aqwert

Reputation: 10789

Using static methods is no issue. Just don't use static state unless you can synchronise access and keep performance

Upvotes: 1

Related Questions