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.

Re: What is "Any instance members are not guaranteed to be thread safe" ? by Marina

Marina
Mon Apr 04 10:14:53 CDT 2005

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.

"ks_lon" <kaykayes@yahoo.com> wrote in message
news:1112627498.067404.294490@g14g2000cwa.googlegroups.com...
> 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.
>



Re: What is "Any instance members are not guaranteed to be thread safe" ? by W

W
Mon Apr 04 10:21:49 CDT 2005

http://en.wikipedia.org/wiki/Thread-safe

--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"ks_lon" <kaykayes@yahoo.com> wrote in message
news:1112627498.067404.294490@g14g2000cwa.googlegroups.com...
> 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.
>



Re: What is "Any instance members are not guaranteed to be thread safe" ? by kaykayes

kaykayes
Tue Apr 05 11:48:23 CDT 2005

"W.G. Ryan eMVP" <WilliamRyan@gmail.com> wrote in message news:<eDv6GoSOFHA.2704@TK2MSFTNGP15.phx.gbl>...
> http://en.wikipedia.org/wiki/Thread-safe
>
> --
> W.G. Ryan, MVP
>
> www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
> "ks_lon" <kaykayes@yahoo.com> wrote in message
> news:1112627498.067404.294490@g14g2000cwa.googlegroups.com...
> > 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.
> >

Cheers guys, I was being a plonker!