dimanche 27 août 2017

Issue with increasing amount of time spent in static property that is using reflection

In this example I have:

internal class SomeClass
{

    private static PropertyInfo[] properties = typeof(SomeCustomClass).GetProperties();

    internal static SomeReturnType SomeMethod()
    {
        System.Diagnostics.Stopwatch s = System.Diagnostics.Stopwatch.StartNew();

        foreach (PropertyInfo property in properties)
        {
         // Nothing
        }
        s.Stop();
        Console.WriteLine(s.Elapsed);
    }
}

I have narrowed down my issue to this piece of code where my console output shows an increasing amount of time almost like there is a leak of some sort. I am executing SomeMethod() in a high volume multithreaded scenario. Any ideas what the problem may be? I assume it has something to do with the static property using reflection but I figured it would only happen once.





Aucun commentaire:

Enregistrer un commentaire