Multithreading Confusion for C# DLL running in ASP.NET

K

Ken Brannigan

Hello,
I am a little confused regarding the creation of a C# DLL that will be
called from ASP.NET. From what I have read ASP.NET is Multithreaded. My
undersatnding of this is that more than one thread can call into my object.
What coding considerations do I need to take for this?? Would the sample
class below need any changes to work under asp.net as to avoid any issues??

Thanks for any help!!
Ken

public class Test
{
//Module Variables.
private string privMyProperty = string.Empty;

public Test()
{
//Default Constructor Stuff.
}

//Property.
public string MyProperty
{
get
{
return privMyProperty;
}
set
{
privMyProperty = value;
}
}

public void Save()
{
//DO SOME WORK THAT USES PROPERTY.
}
}
 
A

Alvin Bruney [MVP]

u only need worry about concurrent access if the class makes use of static
variables and methods which are stateful - global data for example, or for
shared objects - as in the case where you pass an object around to different
threads.

in your example, if this private string privMyProperty was declared like
this private static string privMyProperty and this privMyProperty was
persisted somewhere, you would need to worry about concurrent access.
 
M

Miha Markic

Hi Ken,

As long as your class is not shared among different sessions there is no
problem (static or stored in application cache or something like that)
 
K

Kenneth H. Brannigan

Miha,
Thank you!! That makes sense.
Ken

Miha Markic said:
Hi Ken,

As long as your class is not shared among different sessions there is no
problem (static or stored in application cache or something like that)
 

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