private void SendResponse(StreamWriter writer, OutMessage resp) { FunctionSerializer funcSer = new FunctionSerializer(); BufferSerializer buffSer = new BufferSerializer(); string serialized = JsonConvert.SerializeObject(new { resp.id, resp.callback, resp.data, resp.error }, funcSer, buffSer); mCallbacks [resp.id] = funcSer.callbacks; writer.Write(serialized + "\uFFFF"); }
private void WriterLoop(StreamWriter writer, BlockingCollection <OutMessage> outgoing) { bool running = true; try { while (running) { OutMessage msg = outgoing.Take(); SendResponse(writer, msg); } } catch (InvalidOperationException) { // queue was closed by the producer return; } catch (Exception e) { Console.Error.WriteLine("write loop failed: {0}", e.Message); } }