private void onGettingRegisterResponse(IAsyncResult ar) { int red = 0; try { lock (mStream) { red = mStream.EndRead(ar); } String content = Encoding.Unicode.GetString(mBuf, 0, red); Array.Clear(mBuf, 0, BUFLEN); List <String> messages = new List <string>(); mMP.GetMessages(content, ref messages); for (int i = 0; i < messages.Count; i++) { parseAndRunRegister(messages[i]); mReadOver = true; } } catch (Exception) { } if (!mReadOver) { lock (mStream) { AsyncCallback callback = new AsyncCallback(onGettingRegisterResponse); mStream.BeginRead(mBuf, 0, BUFLEN, callback, null); } } else { if (mStream != null) { mStream.Close(); } mClient.Close(); } }
private void onReadFinished(IAsyncResult ar) { int red = 0; try { lock (mStream) { red = mStream.EndRead(ar); } String content = Encoding.Unicode.GetString(mBuf); Array.Clear(mBuf, 0, BUFLEN); List <String> messages = new List <string>(); mMP.GetMessages(content, ref messages); for (int i = 0; i < messages.Count; i++) { ParseAndRun(messages[i]); mReadOver = true; } if (!mReadOver) { lock (mStream) { AsyncCallback callback = new AsyncCallback(onReadFinished); mStream.BeginRead(mBuf, 0, BUFLEN, callback, null); } } } catch (Exception) { } }