From: Pavol S. <st...@st...> - 2003-02-23 00:44:11
|
You are right, it will throw exception, but foreach it's same (using GetEnumerator and MoveNext too...)... But you can get collection of keys and enumerate throw that collection... So when you remove connection keys collection is unchanged and there is no exception... p. ----- Original Message ----- From: "Carlos Guzmán Álvarez" <car...@te...> To: "Pavol Starek" <pa...@st...> Cc: <fir...@li...> Sent: Sunday, February 23, 2003 1:30 AM Subject: Re: [Firebird-net-provider] blobs > Hello: > > > i think you can remove it becouse unlocked is locked and in while you move > > to next, so you will not read null connection... To clean up unlocked you > > can put that line after while loop... > > Reason for this is: If you have 100 pooled connections first 50 is ok and > > last 50 is old, so you will go throw first 50 and then you will remove 51 > > and GetEnumerator() will reset counter to 0 so you will do it again from > > zero... so you will do 50x50 (litle more) while cycles... > > In my case you will do only 100 cycles... > > > As i remember MoveNext() will throw an exception if i don't make it ( i > will see it again i will try with a foreach too ). > > > > > If im wrong write it... Im just learning your code... > > > No problem it's good thing :) > > > > next think is: > > > > private void RunCleanUp() > > { > > TimeSpan interval = new TimeSpan(0, 0, 10); > > > > while (true) > > { > > -> lock (this) > > { > > CleanUp(null); > > } > > > > Thread.Sleep(interval); > > } > > } > > > > you dont need to lock whole class instance, becouse in CleanUp you are > > working only with unlocked instance variable and its locked there... If you > > have lot of connections (and there is above situation) pool is locked too > > long... > > > You are rigth here, thanks very much :) > > > > > Best regards > Carlos Guzmán Álvarez > Vigo-Spain > > |