예제 #1
0
    public static void ProcessCallback(IAsyncResult Source = null)
    {
        m_MutexCallback.WaitOne();
        while (m_listCallback.Count > 0 || Source != null)
        {
            DebugLog("[ProcessCallback]");
            IAsyncResult result = null;
            if (Source == null)
            {
                result = m_listCallback[0];
                m_listCallback.RemoveAt(0);
            }
            else
            {
                result = Source;
            }
            CReqState asyncState = null;
#if !SHOW_EXCEPTION
            try
            {
#endif
            asyncState = (CReqState)result.AsyncState;
            DebugLog("1");
            HttpWebResponse cRsp = (HttpWebResponse)asyncState.request.EndGetResponse(result);
            DebugLog("2");
            StreamReader cStmRdr = new StreamReader(cRsp.GetResponseStream());
            DebugLog("3");
            string output = string.Empty;
            DebugLog("4");
            output = cStmRdr.ReadToEnd();
            DebugLog("5");
            cStmRdr.Close();
            asyncState.finishcallback(ErrorType.Success, output);
#if !SHOW_EXCEPTION
        }
        // 取不到資料
        catch (WebException e)
        {
            LogMgr.ErrorLog("[FinishWebRequest][ProcessCallback] Message:{0}, Status:{1}", e.Message, e.Source);
            if (asyncState != null)
            {
                asyncState.finishcallback(ErrorType.Error);
            }
            m_MutexCallback.ReleaseMutex();
            throw e;
        }
#endif
        }
        m_MutexCallback.ReleaseMutex();
    }
예제 #2
0
    // 要統一做處理
    static void FinishWebRequest(IAsyncResult result)
    {
        CReqState       asyncState = (CReqState)result.AsyncState;
        HttpWebResponse cRsp       = (HttpWebResponse)asyncState.request.EndGetResponse(result);
        StreamReader    cStmRdr    = new StreamReader(cRsp.GetResponseStream());
        string          output     = string.Empty;

        output = cStmRdr.ReadToEnd();
        cStmRdr.Close();
        asyncState.finishcallback(0, output);
    }