c# - ReadAsync exiting, not able to trace in debug -


i have following code (_ns networkstream)

await getresponse(_ns); btnsend.enabled = true;  private async task getresponse(networkstream stream) {     while (true)     {         var readbuffer = new byte[4096];         var asyncreader = await stream.readasync(readbuffer, 0, readbuffer.length);         txtboxmessagesin.text += encoding.ascii.getstring(readbuffer.toarray()) + environment.newline;         if (asyncreader <= 0) break;     } } 

i seem fill entire buffer expect, btnsend never enabled.

when run in debug mode, while loop runs couple of times, see asyncreader set different values never equals 0 break loop expect, justs exits @ line:

var asyncreader = await stream.readasync(readbuffer, 0, readbuffer.length); 

without generating errors. causing this? need set in visual studio break on type of error?

readasync return 0 when stream ends. how streams work. if stream has not ended (i.e., socket stream, socket still open), readasync (asynchronously) wait stream either read more bytes or end.

i assume other end of socket hanging open not sending more data. in case, stream reads wait either send more bytes or close. there's no exceptions - not exceptional situation. since socket not closed, stream read not return 0, , while loop not exit.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -