Delay varies for different events RRS feed

  • Question

  • I have a custom control with events, and i have a set of code to be executed. I tried the code in various events such as my controls loaded event, in a dependency changed event and also in a Routed event. The time taken to execute the same block of code get various.

    It takes 200 Milliseconds for Loaded, 1100 Milliseconds for dependency changed and 700 for Routed event.

    object emp = new EmployeeInfoViewModel().EmployeeDetails;
    var Records = emp as IEnumerable<object>;
    var itemsSource = Records.Select(x =>
        GetValue(x, "EmployeeID")).Distinct().Select(item =>
             new Elements { IsSelected = true, ActualValue = item, Name = item != null ? item.ToString() : "Test" }).ToList();
    control.ItemsSource = itemsSource;

    In the above code, emp holds a collection of 100000 records and the GetValue method uses a PropertyInfo(Reflection) and returns the data.

    Any ideas, what is happening?


    Wednesday, March 27, 2013 6:20 AM


  • So the code block you have provided varies in execution time or what execution time are you actually measuring?

    If it's the code block you provided, then you should be able to figure out why execution time varies. It might be how those 100000 records are used; are they in memory or read from somewhere.

    If you have measured the code that leads to event, then there actually should be variance, and that's expected as every code that leads to event, key press, Window load, mouse press, is different than other code that leads to different event being raised.

    • Edited by MasaSam Wednesday, March 27, 2013 12:09 PM
    • Proposed as answer by Jason Dot Wang Friday, March 29, 2013 7:05 AM
    • Marked as answer by Jason Dot Wang Thursday, April 4, 2013 5:29 AM
    Wednesday, March 27, 2013 12:07 PM