tags:

views:

64

answers:

2

Hi everyone,

if I put a debuger from starting line one of this code and step through i dont get anything event after the line

    xmlData = reader.ReadToEnd(); 

but if I have debugger on the last line of this code.. where the brace closes, I get everything. i dont know if this only the debuger acting crazy, or a real thing

using (StreamReader reader = new StreamReader(context.Request.InputStream))
{
    xmlData = reader.ReadToEnd();
}

Can anyone tell me whats going on. cause sometimes i am not able to get any data from streamreader, even though the data is sent correctly.

Thanks

+5  A: 

The reader isn't going to perform the actual "read" until the ReadToEnd method is called. What are you trying to do?

Chris Lively
+1. Beat me to it. I should have typed less. ;-)
David Stratton
thats not how it is working though. went i step through it.. it doesnt get any data after ReadToEnd() .. Even though i know for sure data has been sent..it just basic httphandler that captures the request does something with the data and responds back with some data
devforall
Watch out for timeouts. They may trip when you're debugging.
Hans Passant
thats seems to answer the question .. u have any idea y would be delayed sometimes in normal excution.. there is nothing between request that could be causing this ..i mean the code is quite straight forward.. and i dont see any firewalls either.. in between .. wen i run a load test of 30000 i get at least 100 to 150 request that show this behavior..
devforall
@user: Change your load test to send fewer requests per second, then see what happens. You might be knocking the server over.
Chris Lively
+1  A: 

If you put a breakpoint on a line the break occurs before that line gets executed, so it's no surprise that you don't get any data.

But I suspect what you mean is that you place a breakpoint and then step through the code slowly until you reach the end and then check the contents of the variable and find that they are empty.

  • One cause could be a timing issue. It could be that the service you are reading from has timed out.
  • Another cause could be a race-condition in your code.
  • One other unexpected thing that can catch people out is that watches can cause side-effects and stepping through the code causes the watches to be re-evaluated. This can change the state of your program depending on where you put the break-point. You should be careful not to set up a watch on a property that has a side-effect when evaluated.
Mark Byers