예제 #1
0
        private void ReadFileCB(IAsyncResult ar)
        {
            ReadFileStateInfo state = ar.AsyncState as ReadFileStateInfo;

            if (state == null)
            {
                return;
            }
            FileStream fs    = state.ReadFileStream;
            int        count = fs.EndRead(ar);

            if (count > 0)
            {
                state.ResultStream.Write(state.ReadBuffer, 0, count);
                fs.BeginRead(state.ReadBuffer, 0, BUFFER_SIZE, new AsyncCallback(ReadFileCB), state);
            }
            else
            {
                if (fs != null)
                {
                    fs.Close();
                    fs = null;
                }

                state.EndProcessCB(ar);
            }
        }
예제 #2
0
        public void EndProcessRequest(IAsyncResult result)
        {
            ReadFileStateInfo state = result.AsyncState as ReadFileStateInfo;

            if (state == null)
            {
                return;
            }
            state.Context.Response.ContentType = "image/*";
            state.Context.Response.BinaryWrite(state.ResultStream.ToArray());
            state.ResultStream.Close();
        }