views:

260

answers:

2

I suspect this applies to general ASP.Net too but I am not sure.

If I have an action method on a Controller, say MyController.DoSomethingExciting and three clients hit it at "the same time", is it intrinsically thread safe, or do I need to do something to ensure that the three concurrent calls don't interact with each other?

+7  A: 

Local variables in that method will be per-call. I presume (don't know MVC) that the Controller instances are per-request, so any instance members would be safe.

But if there are any static or other shared members, then they are not safe.

John Saunders
You're correct that Controller instances are per-request
roryf
A: 

if the method instantiates all its own variables and does not use any static members then it should be ok in all cases.

It the object is referenced by multiple threads at once and it reads some class level variables multiple times that could be modified by another thread inbetween reads then there could be a problem.

If it only reads data once and doesn't write anything at the class level then multi threading is unlikley to be an issue.

John Nicholas