This project has moved and is read-only. For the latest updates, please go here.

UI Thread Performance Degrades when HttpClient.PostAsync is aborted on App Deactivation

Apr 23, 2014 at 5:42 PM
Firstly, great project! Thanks for publishing it.

I’ve been investigating a performance issue in my Windows Phone 8.0 SL app. What I’ve found is that when the app is deactivated, aborted analytics requests from the HttpClient cause a noticeable slowdown of my app. It appears like something is chewing up UI thread cycles after an abort or cancel occurs. I’ve updated the Microsoft HTTP client library project and have download the source for this project. When I comment out the code in GAServiceManager.DispatchImmediatePayload the issue goes away (but of course no analytics messages are sent).

I've tried switching to a single instance of HttpClient in the GAServiceManager class, rather than creating a new one at each request. I've also tried supplying the HttpClient with a CancelationToken and cancelling when the app is deactivated. All to no avail.

May 2, 2014 at 11:53 PM
Thanks Daniel, would you be able to share a repro project (or provide detailed instructions on how to duplicate)? I looked at the code as well and was unable to come up with anything besides the HttpClient itself being responsible for this but would like to confirm.

One thing you might be able to do is set dispatchPeriod to 0 which will cause the SDK to send all logs immediately. The reason this might help is that by the time you deactivate, there will probably only be 1 log in the queue at most.
May 3, 2014 at 1:05 AM
Hi Tim,

Thanks for taking a look. I tried creating a light weight repro but was unable to see it happening.
In the meantime I replaced WebClient with HttpWebRequest in the GAServiceManager class and removed all the async calls as I thought it possible that something was going awry under the covers. In the end the issue went away, but I think it was a memory leak originating from my code that was actually the culprit. I’m not certain though. When I switch back to the original implementation, I’ll let you know if the issue returns.