Difference between revisions of "Troubleshooting program hangs"

From OPC Labs Knowledge Base
Jump to navigation Jump to search
 
(3 intermediate revisions by the same user not shown)
Line 4: Line 4:
 
The following procedure may help in analyzing the cause of the hang:
 
The following procedure may help in analyzing the cause of the hang:
  
 +
===Part One: Debugger Break===
 
# Create a reproducible scenario in which the hang occurs, and write down the steps needed.
 
# Create a reproducible scenario in which the hang occurs, and write down the steps needed.
# Start the program under Visual Studio debugger ({{Style=menu|Debug -> Start Debugging}}) and trigger the hang. Alternatively, trigger the hang first, and then attach the Visual Studio debugger to the program ({{Style=menu|Debug -> Attach to Process}}). Make sure the proper code types for debugging are enabled (normally "{{Style=item|Managed (v4.6, v4.5, v4.0)}}" and "{{Style=item|Native}}").
+
# Start the program under Visual Studio debugger ({{Style=menu|Debug -> Start Debugging}}) and trigger the hang. Alternatively, trigger the hang first, and then attach the Visual Studio debugger to the program ({{Style=menu|Debug -> Attach to Process}}). When attaching, make sure the proper code types for debugging are enabled (normally "{{Style=item|Managed (v4.6, v4.5, v4.0)}}" and "{{Style=item|Native}}").
 
# Break into the debugger using {{Style=menu|Debug -> Break All}}.
 
# Break into the debugger using {{Style=menu|Debug -> Break All}}.
 +
# Continue to Part Two (there are two alternatives you can choose).
 +
 +
===Part Two: Information Gathering - Through Minidump===
 +
# Perform the {{Style=menu|Debug -> Save Dump As}} command.
 +
# In the {{Style=label|Save Dump As}} dialog, make sure that the {{Style=label|Save as type}} is set to {{Style=item|Minidump with Heap (*.dmp)}}. Select file name and location, and press the {{Style=button|Save}} button.
 +
# Send us the minidump file for analysis.
 +
 +
===Part Two, Alternative: Information Gathering - Through Thread List===
 
# Display the Threads window using {{Style=menu|Debug -> Windows -> Threads}}.
 
# Display the Threads window using {{Style=menu|Debug -> Windows -> Threads}}.
 
# In the Threads window, on '''each''' row in the table under the Location column, expand the call stack by clicking the down arrow on the left side of the column (if present).
 
# In the Threads window, on '''each''' row in the table under the Location column, expand the call stack by clicking the down arrow on the left side of the column (if present).
# Right-click in the area of Threads window, and invoke the {{Style=menu|Select All}} command.
+
# Right-click in the area of {{Style=label|Threads}} window, and invoke the {{Style=menu|Select All}} command.
# Right-click in the area of Threads window, and invoke the {{Style=menu|Copy}} command.
+
# Right-click in the area of {{Style=label|Threads}} window, and invoke the {{Style=menu|Copy}} command.
 
# Paste the resulting into a text file and save it.
 
# Paste the resulting into a text file and save it.
 
# If you have the capability to do so, analyze the contents of the file to check if the hang cause is not in your code.
 
# If you have the capability to do so, analyze the contents of the file to check if the hang cause is not in your code.
Line 16: Line 25:
  
 
Tools other than Visual Studio may provide similar capabilities, but Visual Studio is preferred.
 
Tools other than Visual Studio may provide similar capabilities, but Visual Studio is preferred.
 +
 +
See also: [[Obtaining .NET call stacks in a COM application]]

Latest revision as of 16:46, 11 March 2019

Some problems in the components used or in your code manifest themselves as "hangs": The application stops responding, the method call never returns (or multiple calls on several threads), notifications no longer come in, or a combination of these symptoms. Such problems are usually difficult to diagnose; they are often caused by "deadlocks" of simple, but also sometimes very complicated nature, resulting from a combination of various programming techniques and libraries.

The following procedure may help in analyzing the cause of the hang:

Part One: Debugger Break

  1. Create a reproducible scenario in which the hang occurs, and write down the steps needed.
  2. Start the program under Visual Studio debugger (Debug -> Start Debugging) and trigger the hang. Alternatively, trigger the hang first, and then attach the Visual Studio debugger to the program (Debug -> Attach to Process). When attaching, make sure the proper code types for debugging are enabled (normally "Managed (v4.6, v4.5, v4.0)" and "Native").
  3. Break into the debugger using Debug -> Break All.
  4. Continue to Part Two (there are two alternatives you can choose).

Part Two: Information Gathering - Through Minidump

  1. Perform the Debug -> Save Dump As command.
  2. In the Save Dump As dialog, make sure that the Save as type is set to Minidump with Heap (*.dmp). Select file name and location, and press the Save button.
  3. Send us the minidump file for analysis.

Part Two, Alternative: Information Gathering - Through Thread List

  1. Display the Threads window using Debug -> Windows -> Threads.
  2. In the Threads window, on each row in the table under the Location column, expand the call stack by clicking the down arrow on the left side of the column (if present).
  3. Right-click in the area of Threads window, and invoke the Select All command.
  4. Right-click in the area of Threads window, and invoke the Copy command.
  5. Paste the resulting into a text file and save it.
  6. If you have the capability to do so, analyze the contents of the file to check if the hang cause is not in your code.
  7. Deliver the text file to us for analysis (post on the forums, or send by email).

Tools other than Visual Studio may provide similar capabilities, but Visual Studio is preferred.

See also: Obtaining .NET call stacks in a COM application