In ASP.NET 3.5, we suspect a delegate triggering by a "Timer" will block other method calls. From logs, some function calls will wait for the finishing of the delegate and continue to work.
Is it true? If yes, what workaround can I do?
PS: The delegate contains codes to use WCF to retrieve data and the f开发者_Go百科ollowing code
private void Replace<T>(ref IList<T> src, IList<T> des)
{
lock(src)
{
while (src.Count > 0)
{
GC.SuppressFinalize(src.ElementAt(0));
src.RemoveAt(0);
}
GC.SuppressFinalize(src);
src = des;
}
}
Thanks a lot.
It depends on which Timer
implementation you're using - there are at least three. If you use a Timer
which just fires on the thread pool with no synchronization object, it shouldn't be an issue.
The fact that you're locking for the duration of the call will block anything else locking on the same object, of course.
This has nothing to do with your specific question, but the GC.SuppressFinalize
calls in your code are a huge red flag to me. Because of its intended purpose its use is usually limited to the implementation of the IDisposable
interface. They way you are using it here could be causing resource leaks. Read Implementing Finalize and Dispose to Clean Up Unmanaged Resources for more information.
精彩评论