These days I am investigating freezing UI application problem. It is very painful. No clues.
I tried reading logs of UI application, checking socket connection status, memory and CPU usage. But it does not help. Everything seems fine.
I tried to add logs when entering and leaving locks in UI application. It seems fine. Entering and leaving match.
I also tried Windows debugging tool and ANTS performance profiler. They are not really helpful since freezing does not happen all the time. And Windows debugging tool is kind of difficult to use. You need spend some time to learn how to use it. It is not straightforward telling you what is wrong with your codes.
The problem was finally solved 'by accident'. Somebody changed something and magically UI stopps hangging any more.
Take a look at change history, we found out hanging is caused by cross thread problem of UI application. UI thread creates a new UI object. The handler on the new UI object starts to doing something. The later change is to put these codes in a safe invoke scope. It looks like as followings.
UIObject b = new UIObject(); //For example a button
if ( b.InvokeRequired )
{
// fall into here if new thread is needed
}
else
{
//fall into here if no new thread is needed
}
So top issues I will focus on if unfortunately I have to investigate this problem again
1) CPU and memory usage. They are always the first suspect and easy to check.
2) Threads number of this application. Easy to check.
3) UI update should be covered in safe Invoke/BeginInvoke/EndInvoke scope. Just like the above example.
4) lock problems.
No comments:
Post a Comment