Beispiel #1
0
    void ReadCallBack(IAsyncResult ar)
    {
        StateObject state = ar.AsyncState as StateObject;

        try
        {
            int read = state.ReadStream.EndRead(ar);
            if (read > 0)
            {
                state.ResponseInfo.ResponseContent.Write(state.Buffer, 0, read);
                state.ReadStream.BeginRead(state.Buffer, 0, state.Buffer.Length, ReadCallBack, state);
            }
            else
            {
                state.ReadStream.Close();
                state.HttpWebRequest.Abort();
                if (state.Action != null)
                {
                    state.Action(state.ResponseInfo);
                }
            }
        }
        catch (Exception ex)
        {
            HandException(ex, state);
        }
    }