What is "Any instance members are not guaranteed to be thread safe" ?

  • Thread starter Thread starter ks_lon
  • Start date Start date
K

ks_lon

Hello all,

I was developing an ASP.NET application using c#, and I was thinking
for adding some instance variables for my xyz.aspx like this :-

public class SetCustomers : System.Web.UI.Page
{
private string s_workemail = "";

private void Page_Load(object sender, System.EventArgs e)
{

I however came across this in the Page Class definition :-

Thread Safety
Any public static (Shared in Visual Basic) members of this type are
thread safe. Any instance members are not guaranteed to be thread safe.

so I got confused, my question is, does this mean that my instance
variable s_workemail is NOT thread safe?
i.e if user A and user B access my page and modify the value at the
same time, will I get wrong results? or will there be 2 variables, 1 on
every thread?

Thanks for your help.
 
2 different people accessing your page, means 2 different instances of the
page, and hence of your object. So there are no thread safety issues there,
since each has its own copy.

The issue is when you are launching your own threads in an application. If
both threads work with the object at the same time, there is no guarantee
that your app won't get all screwed up.
 
Back
Top