Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Odd object behaviour. Please explain
Message
 
To
15/11/2004 18:29:11
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00961562
Message ID:
00961680
Views:
7
Chris,
You are correct. The reason I wanted to use a static property was because it is updated from within a static method that is running in it's own separate thread and in order to ensure thread safety. I choose to make it static.

Einar

>Doesn't the use of the "static" keyword retain the value of _CumulativeDataRead as an SBox class member, separate from creation and destruction of the oSBox object?
>
>
>>Hi there I just noticed a odd behaviour from my class. My class is a class that knows how to connect to a device using the ethernet, send some information to the device, retreive a response from the device and then close the connection to the device. Until now I thought things were going smoothly, but today I wanted to improve the speed of the connect,send,receive, disconnect process.
>>
>>In a button click I create my object
>>
>>ALS.Device.SBox oSBox = new ALS.Device.SBox();
>>
>>
>>One of the properties of my class is:
>
>>private static System.Int32 _CumulativeDataRead = 0;
>>public System.Int32 CumulativeDataRead
>>{
>> get{ return SBox._CumulativeDataRead;}
>>}
>
>>
>>Now the first time I click the button every thing is fine (CumulativeDataRead = 0), but the next time I click the button the value returned by CumulativeDataRead is equal to the number of bytes I received with the last transmission (CumulativeDataRead=281). The object oSBox is scoped to the button click method so you think it would be disposed after the button click method is completed. What I ended up doing, for the time beeing, is to add
>>
>>SBox._CumulativeDataRead = 0
>>
>>in the constructor of the class to ensure that the value is reset upon creation of the object oSBox and this works.
>>
>>So my question is: Why does .NET "reuse" my old object the 2nd time I click the button?
>>
>>Please let me know your throughts on this issue and let me know if you need further information from me.
>>
>>Thanks,
>>Einar
Semper ubi sub ubi.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform