SqlClient freeing resources is slow (but not every time)
Question
I have this problem for a very long time, but we are about to release, and it must be fixed.
I have an application, and in that application, I can call another (it can be the same application, but with different parameters).
A choice we made is to disable the caller until the called is up.
When I close the called, in some cases, there is a time for freeing ressources whitch lasts about 1500 ms, but not every time.
I used DotTrace to see what happen, and here is the stack :
As we can see, the Finalize methode lasts 1500 ms, and I don't know why !!
For some programs, it only take a few ms.
So, if someone have an idee, ....
Thx, and Merry Christmas !
Solution
I found it!
I do not know why, but I solved the problem by adding a GC.Collect ()
and SqlConnection.ClearPool (_Connection);