Date: 06/01/05 (C Sharp) Keywords: no keywords Hello all. private ArrayList ExecuteCommand(string cmd) { cmd_count += 1; string command = CMD_PREFIX + cmd; ArrayList buffer = new ArrayList(); byte[] data = System.Text.Encoding.ASCII.GetBytes(command.ToCharArray()); string result; try { nStream.Write(data,0,data.Length); while((result = rStream.ReadLine()) != null) { buffer.Add(result); } } catch { throw new CommandException(cmd); } return buffer; } Pretty straightforward, right? nStream is a network stream that operates over a TCP connection to the MS Exchange server. The whole thing works (or should) over IMAP protocol. CMD_PREFIX is just a property that creates a tag for the command. rStream is an instance of StreamReader class operating over the same connection. The problem: The while loop freezes the program. Function calls go like this: Login() function is called that calls Connect() to establish the TCP connection. If that doesn't fail, Login() then calls ExecuteCommand and passes it the LOGIN command to be sent to the server. ExecuteCommand() sends the command in byte form and then reads the result into an array that's returned to Login. For some reason, it goes through the above while() loop once just fine. On the second go, it gets as far as the condition and then freezes. There are no error messages, it doesn't break out of the loop, doesn't continue in the loop... it just does nothing else. LOGIN should return only one line of output, so I would expect the program to break out of the while loop, return the buffer, and be done with it. Also, (and I'm using VS.NET to debug this) when I step into ExecuteCommand, I can no longer view the contents of local variables for some reason. So, there's that... I've absolutely no idea what's going on, so any help would be greatly appreciated. Thanks! Update: apparently if I wait half an hour, the Exchange server times me out, at which point breaking out of the while loop goes through and the program continues as normal... hrm. That'd mean the problem lies in ReadLine somewhere (because the server sends the timeout goodbye message over the stream and it is read fine)... *goes off to think* Source: http://www.livejournal.com/community/csharp/30055.html
|