public Thread sendRequestAsync(HttpRequest request, AwaitMessageCallback callBack) { request.addHeader("Host", servername); string thisstring = request.ToString(); string sendme = request.ToString(); byte[] outBytes = Encoding.UTF8.GetBytes(sendme); //try catch here with a fail callback and timeout timer stream.Write(outBytes, 0, outBytes.Length); stream.Flush(); Thread listenThread; listenThread = new Thread(() => awaitMessageAsync(callBack)); listenThread.Start(); return(listenThread); }
/// <summary> /// /// MOVED the requesting to a new thread and added the callBack error /// /// </summary> /// <param name="request"></param> /// <param name="callBack">response null if exception. exception null otehrwise</param> /// <returns></returns> public Thread sendRequestAsync(HttpRequest request, AwaitMessageCallback callBack) { Thread listenThread; listenThread = new Thread(() => { try { request.addHeader("Host", servername); string thisstring = request.ToString(); string sendme = request.ToString(); byte[] outBytes = Encoding.UTF8.GetBytes(sendme); //try catch here with a fail callback and timeout timer stream.Write(outBytes, 0, outBytes.Length); stream.Flush(); } catch (Exception ex) { callBack(null, ex); return; } callBack(awaitMessage(), null); //Call back should not catch errors }); listenThread.Start(); return listenThread; }
private void awaitMessageAsync(AwaitMessageCallback callBack) { callBack(awaitMessage()); }