Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Odd object behaviour. Please explain
Message
 
À
15/11/2004 18:25:58
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00961562
Message ID:
00961582
Vues:
6
Bonnie,

Hmm I guess that is right, but the reason I made that particular property static was because I wanted to make sure it is thread safe. The property is updated from a receiving thread spawned from the connect method for the oSBox object.
Is there a problem updating a non-static property from a different thread?

Einar

>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
Semper ubi sub ubi.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform