Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Odd object behaviour. Please explain
Message
From
15/11/2004 18:25:58
 
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00961562
Message ID:
00961568
Views:
4
Einar,

I think it's because you have the _CumulativeDataRead declared as static. Get rid of the static keyword and all should be good.

~~Bonnie



>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
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform