Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Odd object behaviour. Please explain
Message
De
15/11/2004 18:29:11
Chris Bohling
Myers and Stauffer LC
Shawnee, Kansas, États-Unis
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00961562
Message ID:
00961569
Vues:
4
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
Christopher Bohling, Consultant
http://www.ChristopherBohling.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform