c# - Stream with openWrite not writing until it is closed -


i have stream writer opens using webclient.openwrite call. simplified case, assume reader reading multiple of datachunksize.

using (stream writer = mywebclient.openwrite(myuristring) {     using (filestream reader = new filestream(myfilename, filemode.open, fileaccess.read)     {         for(int = 0; < reader.length; += datachunksize)         {             byte[] data = new byte[datachunksize];             reader.read(data, 0, datachunksize);             writer.write(data, 0, datachunksize);         }          reader.close();         reader.dispose();     }      writer.close();     writer.dispose(); } 

my data size of 2 datachunksizes. however, not send data (no data received) until writer.close() call called, sends first datachunksize worth of data...the second datachunksize of data never sent.

how can send after every write call? tried adding writer.flush() did not help.

thanks.

i think issue because last chunk perhaps not full length expect (datachunksize). also, add flush force each write there , if needed (thou not sure if flush work). try changing loop contents this...

byte[] data = new byte[datachunksize]; int bytesread = reader.read(data, 0, datachunksize); writer.write(data, 0, bytesread); writer.flush(); 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -