private async Task <NetMessage> PostMsg(sdk.NetMessage msg, string backcmd) { //var _id = this.sendMsgID; //msg.Params["_id"] = BitConverter.GetBytes(this.sendMsgID); //this.sendMsgID++; UInt64 _id = await Send(msg); //想要这个消息 wantMessage[_id] = backcmd; //加入发送队列 //wantsend.Enqueue(msg.ToBytes()); //var bytes = msg.ToBytes(); //ArraySegment<byte> buffer = new ArraySegment<byte>(bytes); //await websocket.SendAsync(buffer, System.Net.WebSockets.WebSocketMessageType.Binary, true, System.Threading.CancellationToken.None); //还没搞清楚为何postmsg 一旦await 等待就会闪退 var _wait = Wait(_id); Task.WaitAll(_wait); return(_wait.Result); //return await Wait(_id); //await Task.Delay(1); //return await Wait(_id); }
public async Task <UInt64> Send(sdk.NetMessage msg) { UInt64 _id = 0; lock (this) { _id = this.sendMsgID; this.sendMsgID++; } msg.Params["_id"] = BitConverter.GetBytes(_id); wantsend.Enqueue(msg.ToBytes()); return(_id); }
public async Task <UInt64> Send(sdk.NetMessage msg) { UInt64 _id = 0; lock (this) { _id = this.sendMsgID; this.sendMsgID++; } msg.Params["_id"] = BitConverter.GetBytes(_id); var bytes = msg.ToBytes(); ArraySegment <byte> buffer = new ArraySegment <byte>(bytes); await websocket.SendAsync(buffer, System.Net.WebSockets.WebSocketMessageType.Binary, true, System.Threading.CancellationToken.None); return(_id); }