I am trying to debug some async code and when I try to step through the lines of code in the debugger, everything goes fine until it reaches Line 18 in the snippet below. After it runs that line, the debugger stops and VS exits debugging mode. Is there a particular way to debug an async program that I am missing or is there something in the code that is incorrect?
1. private static void ReadAsynchronously(IAsyncResult ar)
2. {
3. StateObject state = (StateObject)ar.AsyncState;
4. //Data buffer for incoming data
5. byte[] bytes = new byte[1024];
6.
7. Socket readHandler = state.workSocket;
8.
9. //Flag variable for identifying the End of Character from the read message
10. bool pFlag = false;
11.
12. //String variable for store the reading data from the client socket
13. string content = string.Empty;
14. string data = string.Empty;
15.
16.
17. // Read data from the client socket.
18. int read = readHandler.EndReceive(ar);
19.
20. if (read > 0)
21. {
........
You could be missing an Exception in the EndRead call, try using a catch block and check: